我正在尝试用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: "times new
roman", "new york", times, serif; font-size: 14pt; color:
rgb(0, 0, 0);"><div><br></div></body>
你有任何想法在邮件中写一些文字吗?
谢谢。
LCS
在你写的倒数第二行:
texte = driver.find_element_id("tinymce")
方法调用不应该是:
texte = driver.find_element_by_id("tinymce")
(注意“by”)
是因为类属性末尾有一些额外的空间吗?