Selenium Automation - 用邮件写文本

问题描述 投票:-2回答:2

我正在尝试用Selenium编写一个python程序,它在以下网站上编写和发送邮件:http://www.laposte.net/accueil

这是我的代码:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys


driver = webdriver.Chrome() 
driver.get("https://www.laposte.net/accueil")

pseudo = driver.find_element_by_name("login")
mdp = driver.find_element_by_name("password")

pseudo.send_keys("[email protected]")
mdp.send_keys("Testselenium1")

pseudo.submit()

newmess = driver.find_element_by_id("zb__NEW_MENU")
newmess.click()

destinataire = driver.find_element_by_id("zv__COMPOSE-1_to_control")
destinataire.send_keys("[email protected]")

objet = driver.find_element_by_id("zv__COMPOSE-1_subject_control")
objet.send_keys("Test selenium")

texte = driver.find_element_by_xpath("//body[@class='mceContentBody']")
texte.send_keys("Test")

我的代码有效,但我无法在我的正文中添加一些文字。

我收到此错误:无法找到元素:{“method”:“xpath”,“selector”:“// body [@ class ='mceContentBody']”}

有关信息,文本框的HTML代码是:

<body id="tinymce" class="mceContentBody "     
onload="window.parent.tinyMCE.get('DWT48_content').onLoad.dispatch();" 
contenteditable="true" dir="LTR" style="font-family: &quot;times new 
roman&quot;, &quot;new york&quot;, times, serif; font-size: 14pt; color: 
rgb(0, 0, 0);"><div><br></div></body>   

你有任何想法在邮件中写一些文字吗?

谢谢。

LCS

java python selenium automation
2个回答
1
投票

在你写的倒数第二行:

texte = driver.find_element_id("tinymce")

方法调用不应该是:

texte = driver.find_element_by_id("tinymce")

(注意“by”)


0
投票

是因为类属性末尾有一些额外的空间吗?

© www.soinside.com 2019 - 2024. All rights reserved.