找不到包含selenium(python)的电子邮件正文

2024-05-16 16:31:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图让一个机器人(硒)发送电子邮件使用protonmail。你知道吗

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

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"]"}

Tags: brdivsendidbydriverbodyelement
2条回答

我用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"));

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

我认为你的xpath行不通。尝试在用户名/密码字段中查找id或绝对xpath。
用textbox或textarea搜索输入标记。。。然后将值发送到web元素。。。我想你不能将值发送到分区标记。。

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

相关问题 更多 >