python selenium實現(xiàn)發(fā)送帶附件的郵件代碼實例
更新時間:2019年12月10日 11:40:12 作者:風聲~~
這篇文章主要介紹了python selenium實現(xiàn)發(fā)送帶附件的郵件代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
這篇文章主要介紹了python selenium實現(xiàn)發(fā)送帶附件的郵件代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
163郵件登錄首頁
登錄成功斷言是否有退出按鈕
點擊退出退出登錄
代碼如下
from selenium import webdriver import unittest import time class VisitSogouByChrome(unittest.TestCase): def setUp(self): # 啟動Chrome瀏覽器 self.driver = webdriver.Chrome(executable_path = "e:\\chromedriver.exe") def test_sendEmail(self): # 訪問163郵箱的首頁 self.driver.get("https://mail.163.com/") # 打印當前網(wǎng)頁的網(wǎng)址 self.driver.maximize_window() #點擊密碼登錄 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')]") # 切換進登錄框的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) #點擊“寫信”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) # 切換進入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("實現(xiàn)寫郵件,上傳附件的功能自動化用了。。。。。。。。") self.driver.switch_to.default_content() #點擊“發(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()
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- python selenium 執(zhí)行完畢關閉chromedriver進程示例
- Python SELENIUM上傳文件或圖片實現(xiàn)過程
- 詳解pyinstaller selenium python3 chrome打包問題
- Python使用selenium + headless chrome獲取網(wǎng)頁內(nèi)容的方法示例
- 基于python的selenium兩種文件上傳操作實現(xiàn)詳解
- Python進階之使用selenium爬取淘寶商品信息功能示例
- python+selenium select下拉選擇框定位處理方法
- python3 selenium自動化 frame表單嵌套的切換方法
相關文章
pytest用例間參數(shù)傳遞的兩種實現(xiàn)方式示例
pytest提供了許多運行命令以供定制化運行某一類測試用例或者某個測試用例等,下面這篇文章主要給大家介紹了關于pytest用例間參數(shù)傳遞的兩種實現(xiàn)方式,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考下2021-12-12使用python讀取csv文件快速插入數(shù)據(jù)庫的實例
今天小編就為大家分享一篇使用python讀取csv文件快速插入數(shù)據(jù)庫的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-06-06