找不到带有硒的电子邮件正文(python)



我试图让机器人(硒(使用质子邮件发送电子邮件。

一旦机器人找到撰写按钮来发送电子邮件,它就会粘贴收件人和主题:

Recipients = driver.find_element_by_name('autocomplete')
Recipients.send_keys(email)
subject = driver.find_element_by_xpath('/html/body/div[2]/form    [1]/div/div[2]/div[5]/input')
subject.send_keys('Daily Report')

当我尝试找到电子邮件的正文以粘贴实际消息时,问题就来了。

这是我尝试用来寻找解决方案的代码:

body = driver.find_element_by_class_name('editor-container fill')
body.send_keys('Sample text ')
--FAIL
body = driver.find_element_by_id('composer1576347472730')
body.send_keys('Sample text ')
--FAIL
body = driver.find_element_by_xpath('/html/body/div[1]')
--FAIL

我还尝试找到我认为应该是正文的元素的 xpath,但它也没有工作,也没有尝试获取div 或 id 的 xpath。

这是页面元素本身:

<div class="angular-squire-wrapper fill"> <iframe border="0" marginwidth="0"
marginheight="0" class="squireIframe" id="composer1576347472730" 
frameborder="0"></iframe> </div>

<body marginwidth="0" marginheight="0" contenteditable="true" data-enable
grammarly="false"><div><br></div><div><br></div><div 
class="protonmail_signature_block"><div class="protonmail_signature_block-
user protonmail_signature_block-empty"><br></div><div 
class="protonmail_signature_block-proton">Sent with <a target="_blank"
href="https://protonmail.com">ProtonMail</a> Secure Email.<br></div></div></body>

这是我得到的错误:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="composer1576347472730"]"}

我认为你的 xpath 不起作用。尝试在用户名/密码字段中查找 id 或绝对 xpath。
使用文本框或文本区域搜索输入标签...然后将值发送到 Web 元素... 我认为您无法将值发送到除法标签。.

请参阅以下链接
https://www.geeksforgeeks.org/browser-automation-using-selenium/https://www.geeksforgeeks.org/facebook-login-using-python/

我用java做程序,我运行gmail脚本,希望这对你有帮助。

WebDriver driver = new FirefoxDriver();
driver.get("https://mail.google.com/");

WebElement Username = driver.findElement(By.xpath("//*[@id="identifierId"]"));
Username.sendKeys("username@gmail.com");
driver.findElement(By.xpath("//div[@id='identifierNext']/span/span")).click();
WebDriverWait wait = new WebDriverWait(driver, 40);
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//div[@id='password']/div/div/div/input"))));
WebElement Password =driver.findElement(By.xpath("//div[@id='password']/div/div/div/input"));
Password.sendKeys("password");
driver.findElement(By.xpath("//div[@id='passwordNext']/span")).click();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS) ;
driver.findElement(By.xpath("//div[@id=':k1']/div/div")).click();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS) ;
WebElement Data = driver.findElement(By.xpath("//*[@id=":q6"]"));
//Using string
String body = "Hi all";
Data.sendKeys(body);
//Using keys
Data.sendKeys(Keys.chord(Keys.CONTROL,"v"));

对于隐式-显式等待,请使用此链接

最新更新