python3+selenium實現(xiàn)126郵箱登陸并發(fā)送郵件功能
更新時間:2019年01月23日 10:15:10 作者:小小小小人ksh
這篇文章主要為大家詳細介紹了python3+selenium實現(xiàn)126郵箱登陸并發(fā)送郵件功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了python3實現(xiàn)126郵箱登陸并發(fā)送郵件的具體代碼,供大家參考,具體內(nèi)容如下
基于selenium,使用chrome瀏覽器,完成126郵箱登陸并發(fā)送發(fā)郵件功能,暫時未封裝。
from selenium import webdriver
# 導入顯示等待類
from selenium.webdriver.support.ui import WebDriverWait
# 導入期望場景類
from selenium.webdriver.support import expected_conditions as EC
# 導入By類
from selenium.webdriver.common.by import By
import time
#瀏覽器驅(qū)動放在了c:\\Python36\\Scripts目錄下,無需指定參數(shù)
driver= webdriver.Chrome()
driver.get("https://mail.126.com/")
time.sleep(3)
####登陸
driver.switch_to.frame("x-URS-iframe")
user_name = driver.find_element_by_xpath('//*[@name="email"]')
#將xxxxxxx替換為自己的用戶名
user_name.send_keys('xxxxxxx')
pass_word = driver.find_element_by_xpath('//*[@name="password"]')
#將11111111111替換為自己的密碼
pass_word.send_keys('11111111111')
button = driver.find_element_by_id("dologin")
button.click()
driver.switch_to.default_content()
time.sleep(3)
####寫郵件
wait = WebDriverWait(driver,10,0.2)
##wait.until(EC.visibility_of_element_located((By.XPATH,"http://span[text()='發(fā)送']")))
wait.until(EC.visibility_of_element_located((By.XPATH,"http://a[contains(text(),'退出')]")))
driver.find_element_by_xpath('//span[text()="寫 信"]').click()
driver.find_element_by_xpath('//input[@tabindex="1" and @role="combobox"]').\
send_keys("1234h@qq.com")
driver.find_element_by_xpath('//input[@tabindex="1" and @class="nui-ipt-input"]').\
send_keys("測試郵件")
driver.find_element_by_xpath('//input[@type="file"]').send_keys("f:\\b.txt")
time.sleep(5)
wait.until(EC.visibility_of_element_located((By.XPATH,"http://span[text()='上傳完成']")))
driver.switch_to.frame(driver.find_element_by_xpath('//iframe[@tabindex=1]'))
driver.execute_script("document.getElementsByTagName('body')[0].innerHTML='<b>郵件的正文內(nèi)容<b>;'")
driver.switch_to.default_content()
##發(fā)送
driver.find_element_by_xpath('//span[text()="發(fā)送"]').click()
time.sleep(5)
assert '發(fā)送成功' in driver.page_source
logout_link=driver.find_element_by_xpath("http://a[text()='退出']")
time.sleep(3)
assert u"登錄" in driver.page_source
driver.quit()
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
tensorflow轉(zhuǎn)onnx的實現(xiàn)方法
本文主要介紹了tensorflow轉(zhuǎn)onnx的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-03-03
使用Python一鍵提取PDF中的表格到Excel的方法詳解
從PDF文件獲取表格中的數(shù)據(jù),也是日常辦公容易涉及到的一項工作,一個一個復制吧,效率確實太低了,用Python從PDF文檔中提取表格數(shù)據(jù),并寫入Excel文件,灰?;页8咝?本文就給大家介紹一下如何使用Python一鍵提取PDF中的表格到Excel,需要的朋友可以參考下2023-08-08
解決import tensorflow as tf 出錯的原因
這篇文章主要介紹了解決import tensorflow as tf 出錯的原因,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-04-04

