python selenium實(shí)現(xiàn)發(fā)送帶附件的郵件代碼實(shí)例
這篇文章主要介紹了python selenium實(shí)現(xiàn)發(fā)送帶附件的郵件代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
163郵件登錄首頁(yè)
登錄成功斷言是否有退出按鈕
點(diǎn)擊退出退出登錄
代碼如下
from selenium import webdriver import unittest import time class VisitSogouByChrome(unittest.TestCase): def setUp(self): # 啟動(dòng)Chrome瀏覽器 self.driver = webdriver.Chrome(executable_path = "e:\\chromedriver.exe") def test_sendEmail(self): # 訪問163郵箱的首頁(yè) self.driver.get("https://mail.163.com/") # 打印當(dāng)前網(wǎng)頁(yè)的網(wǎng)址 self.driver.maximize_window() #點(diǎn)擊密碼登錄 self.pwd_link = self.driver.find_element_by_xpath("http://a[text()='密碼登錄']") self.pwd_link.click() #找到登錄框的iframe login_input_iframe = self.driver.find_element_by_xpath("http://iframe[contains(@id,'x-URS-iframe')]") # 切換進(jìn)登錄框的iframe self.driver.switch_to.frame(login_input_iframe) self.user_name = self.driver.find_element_by_xpath("http://input[@name='email']") self.pass_wd = self.driver.find_element_by_xpath("http://input[@name = 'password']") self.login_button =self.driver.find_element_by_xpath("http://a[@id ='dologin']") #清空用戶名 self.user_name.clear() self.user_name.send_keys("ff_gaofeng") self.pass_wd.send_keys("XXX") self.login_button.click() time.sleep(5) #點(diǎn)擊“寫信”button self.writer_button = self.driver.find_element_by_xpath("http://span[text()='寫 信']") self.writer_button.click() time.sleep(2) #輸入收件人的郵箱 self.addressee = self.driver.find_element_by_xpath("http://input[contains(@aria-label,'收件人地址輸入框')]") self.addressee.send_keys('ff_gaofeng@163.com') #輸入郵件主題 self.title = self.driver.find_element_by_xpath("http://input[contains(@id,'subjectInput')]") self.title.send_keys('發(fā)給自己的一封郵件') #上傳文件 self.uppload_file_link = self.driver.find_element_by_xpath("http://input[@type = 'file']") #self.uppload_file_link = self.driver.find_element_by_xpath("http://a[text()='添加附件']") self.uppload_file_link.send_keys(r"D:\1.py") time.sleep(5) # 切換進(jìn)入boby的iframe #boby_iframe = self.driver.find_element_by_xpath("http://iframe[@class='APP-editor-iframe']") #self.driver.switch_to.frame(boby_iframe) self.driver.switch_to.frame(self.driver.find_element_by_xpath("http://iframe[@class='APP-editor-iframe']")) # 輸入郵件正文內(nèi)容 self.body = self.driver.find_element_by_xpath("html/body") self.body.send_keys("實(shí)現(xiàn)寫郵件,上傳附件的功能自動(dòng)化用了。。。。。。。。") self.driver.switch_to.default_content() #點(diǎn)擊“發(fā)送”按鈕 self.send_email = self.driver.find_element_by_xpath("http://header//span[text()='發(fā)送']") self.send_email.click() def tearDown(self): # 退出IE瀏覽器 self.driver.quit() if __name__ == '__main__': unittest.main()
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- python selenium 執(zhí)行完畢關(guān)閉chromedriver進(jìn)程示例
- Python SELENIUM上傳文件或圖片實(shí)現(xiàn)過程
- 詳解pyinstaller selenium python3 chrome打包問題
- Python使用selenium + headless chrome獲取網(wǎng)頁(yè)內(nèi)容的方法示例
- 基于python的selenium兩種文件上傳操作實(shí)現(xiàn)詳解
- Python進(jìn)階之使用selenium爬取淘寶商品信息功能示例
- python+selenium select下拉選擇框定位處理方法
- python3 selenium自動(dòng)化 frame表單嵌套的切換方法
相關(guān)文章
python簡(jiǎn)單線程和協(xié)程學(xué)習(xí)心得(分享)
下面小編就為大家?guī)硪黄猵ython簡(jiǎn)單線程和協(xié)程學(xué)習(xí)心得(分享)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-06-06pytest用例間參數(shù)傳遞的兩種實(shí)現(xiàn)方式示例
pytest提供了許多運(yùn)行命令以供定制化運(yùn)行某一類測(cè)試用例或者某個(gè)測(cè)試用例等,下面這篇文章主要給大家介紹了關(guān)于pytest用例間參數(shù)傳遞的兩種實(shí)現(xiàn)方式,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2021-12-12關(guān)于如何使用python的logging庫(kù)
這篇文章主要介紹了關(guān)于如何使用python的logging庫(kù),logging是Python標(biāo)準(zhǔn)庫(kù)中用于記錄日志的模塊。它提供了一種簡(jiǎn)單但靈活的方法來記錄程序中的事件,以便稍后進(jìn)行調(diào)試和分析,需要的朋友可以參考下2023-04-04使用python讀取csv文件快速插入數(shù)據(jù)庫(kù)的實(shí)例
今天小編就為大家分享一篇使用python讀取csv文件快速插入數(shù)據(jù)庫(kù)的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-06-06簡(jiǎn)單談?wù)凱ython中函數(shù)的可變參數(shù)
和C語言一樣,Python中也有可變參數(shù)函數(shù),即一個(gè)函數(shù)可以接收多個(gè)參數(shù),而這些參數(shù)的個(gè)數(shù)在函數(shù)調(diào)用之前事先是不知道的。下面這篇文章我們來介紹下python中的可變參數(shù)2016-09-09