selenium_163邮箱登录、发送邮件
from selenium import webdriver import time driver = webdriver.Chrome(r'D:\chromedriver_win32\chromedriver.exe') #最大窗口 driver.maximize_window() # 进入163邮箱 driver.get('https://mail.163.com/') # 隐形等待 driver.implicitly_wait(5) # 账号密码登录 ele = driver.find_element_by_id('switchAccountLogin').click() #进入表单 ele1=driver.find_element_by_xpath('//*[@id="loginDiv"]/iframe') driver.switch_to.frame(ele1) #执行登录操作 driver.find_element_by_name("email").clear() driver.find_element_by_name("email").send_keys('*******') driver.find_element_by_name("password").clear() driver.find_element_by_name("password").send_keys('******') driver.find_element_by_id('dologin').click() driver.switch_to.default_content() #写信 driver.find_element_by_xpath('//*[@id="_mail_component_24_24"]/span[2]').click() driver.find_element_by_class_name('nui-editableAddr-ipt').clear() driver.find_element_by_class_name('nui-editableAddr-ipt').send_keys('*******@qq.com') driver.find_elements_by_class_name("nui-ipt-input")[2].clear() #driver.find_elements_by_class_name("nui-ipt-input")[2].send_keys("发送邮件测试") driver.find_element_by_xpath('//*[contains(@id,"subjectInput")]').send_keys('发送邮件测试') frame=driver.find_element_by_class_name('APP-editor-iframe') driver.switch_to.frame(frame) driver.find_element_by_class_name('nui-scroll').send_keys('12345') driver.switch_to.default_content() #发送 #163有2个发送按钮,第一个 #driver.find_element_by_xpath("//div[@class='nui-toolbar-item']/div/span[2]").click() #第二2个 driver.find_element_by_xpath('//*[@class="jp0"]/div/span[2]').click() time.sleep(5) #截屏 driver.get_screenshot_as_file(r'./test.png') #退出 driver.find_element_by_xpath('//*[@id="_mail_component_128_128"]/a').click()