python编程快速上⼿之第11章实践项⽬参考答案(11.11.1)from selenium import webdriver
from selenium.webdrivermon.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdrivermon.by import By
from time import sleep
userid=input('username')
passid=input('password')
sendtxt="hello"#邮件内容
sendto=input('sendto')
#打开Firefox
driver = webdriver.Firefox()
<('mail.10086/')#邮箱⽹址
#填写⽤户名
emailElem = driver.find_element_by_id('txtUser')
emailElem.send_keys(userid)#⽤户名
#填写密码
passwordElem = driver.find_element_by_id('txtPass')
passwordElem.send_keys(passid)#密码
passwordElem.submit()
#写邮件
sleep(10)
write=driver.find_element_by_id('btn_compose')
write.click()
sleep(10)
iframe_xpath = "//iframe[contains(@id,'compose_')]"
#写信页所在的iframe的xpath路径,通过⽕狐浏览器的firebug插件可以查看到是在⼀个iframe的页⾯内
iframe = driver.find_element_by_xpath(iframe_xpath)
driver.switch_to_frame(iframe)
python新手代码userid
sleep(5)
driver.find_element_by_id('toContaine').send_keys(sendto)
driver.find_element_by_id('txtSubject').send_keys(sendtxt)
driver.find_element_by_id('topSend').click()

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。