#encoding=utf-8
count =0
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
browser = webdriver.Chrome('C:\Python27\Scripts\chromedriver.exe')
browser.maximize_window()
browser.get('https://mail.qq.com')
browser.switch_to.frame("login_frame")
browser.find_element_by_id('switcher_plogin').click()
browser.find_element_by_class_name('inputstyle').send_keys('XXXXXXXXXX')
browser.find_element_by_id('p').send_keys('XXXXXXXXXX')
browser.find_element_by_id('login_button').click()
time.sleep(6)
useraddr=browser.find_element_by_id('useraddr').text
if useraddr=='XXXXXXXXX@qq.com':
browser.find_element_by_id('composebtn').click()
time.sleep(5)
browser.switch_to.frame(browser.find_element_by_id('mainFrame'))
browser.find_element_by_xpath("//*[@id='toAreaCtrl']/div[2]/input").send_keys('XXXXXXXXXXXXXX')
browser.find_element_by_id('subject').send_keys('i send this message by PythonScript ! HAHA')
try:
zhegnwen=browser.find_element_by_xpath("//*[@id='QMEditorArea']/table/tbody/tr/td/iframe")
browser.switch_to_frame(zhegnwen)
browser.find_element_by_xpath("/html/body").send_keys('ceshijieguo')
browser.switch_to.default_content()
browser.switch_to.frame(browser.find_element_by_id('mainFrame'))
time.sleep(2)
browser.find_element_by_css_selector("#toolbar > div > a:nth-child(1)").click()
time.sleep(5)
finally:
browser.switch_to.default_content()
browser.find_element_by_link_text('退出').click()
time.sleep(5)
browser.quit()
Python+selenium QQ邮箱登录+写信+发送+退出
最新推荐文章于 2023-11-20 15:53:40 发布