python selenium實(shí)現(xiàn)發(fā)送帶附件的郵件代碼實(shí)例
這篇文章主要介紹了python selenium實(shí)現(xiàn)發(fā)送帶附件的郵件代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
163郵件登錄首頁
登錄成功斷言是否有退出按鈕
點(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郵箱的首頁
self.driver.get("https://mail.163.com/")
# 打印當(dāng)前網(wǎng)頁的網(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()
以上就是本文的全部內(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)頁內(nèi)容的方法示例
- 基于python的selenium兩種文件上傳操作實(shí)現(xiàn)詳解
- Python進(jìn)階之使用selenium爬取淘寶商品信息功能示例
- python+selenium select下拉選擇框定位處理方法
- python3 selenium自動(dòng)化 frame表單嵌套的切換方法
相關(guān)文章
python中elasticsearch_dsl模塊的使用方法
這篇文章主要介紹了python中elasticsearch_dsl模塊的使用方法,elasticsearch-dsl是基于elasticsearch-py封裝實(shí)現(xiàn)的,提供了更簡便的操作elasticsearch的方法2022-09-09
Python字典操作詳細(xì)介紹及字典內(nèi)建方法分享
這篇文章主要介紹了Python字典操作詳細(xì)介紹及字典內(nèi)建方法分享,具有一定借鑒價(jià)值,需要的朋友可以參考下2018-01-01
pandas按若干個(gè)列的組合條件篩選數(shù)據(jù)的方法
下面小編就為大家分享一篇pandas按若干個(gè)列的組合條件篩選數(shù)據(jù)的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-04-04
Python使用multiprocessing如何實(shí)現(xiàn)多進(jìn)程
這篇文章主要介紹了Python使用multiprocessing如何實(shí)現(xiàn)多進(jìn)程問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-02-02

