<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Python+Selenium+Webdriver+unittest 實現登錄126郵箱

      第一版:登錄

      #encoding=utf-8
      import unittest
      import time
      from selenium import webdriver
      from selenium.webdriver import ActionChains
      from selenium.common.exceptions import TimeoutException
      from selenium.webdriver.common.keys import Keys
      
      
      class setPageLoadTime(unittest.TestCase):
          def setUp(self):
              self.driver = webdriver.Chrome()
      
          def test_PageLoadTime(self):
              # 設定頁面加載限制時間為4秒
              self.driver.set_page_load_timeout(4) #重點,限制超時時間
              self.driver.maximize_window()
              try:
                  startTime = time.time()
                  self.driver.get("http://mail.126.com")
              except TimeoutException:
                  print (u'頁面加載超過設定時間,超時')
                  # 當頁面加載時間超過設定時間,
                  # 通過執行Javascript來stop加載,然后繼續執行后續動作
                  self.driver.execute_script('window.stop()')
              end = time.time() - startTime
              print (end)
              # 切換進frame控件
              self.driver.switch_to.frame(self.driver.find_element_by_xpath("//iframe[contains(@id,'x-URS-iframe')]"))
              # 獲取用戶名輸入框
              time.sleep(5)
              userName = self.driver.find_element_by_xpath("//input[@data-placeholder='郵箱帳號或手機號碼']")
              # 輸入用戶名
              userName.send_keys("******")
              # 獲取密碼輸入框
              pwd = self.driver.find_element_by_xpath("//input[@data-placeholder='輸入密碼' and @name='password']")
              # 輸入密碼
              pwd.send_keys("*******")
              # 發送一個回車鍵
              pwd.send_keys(Keys.RETURN)
              time.sleep(5)
              assert u"退出" in self.driver.page_source
      
          def tearDown(self):
              self.driver.quit()
      
      if __name__ == '__main__':
          unittest.main()

       結果:

       

      第二版:登錄+發送郵件

      #encoding=utf-8
      import unittest,time,traceback
      from selenium import webdriver
      from selenium.webdriver.support.ui import WebDriverWait
      from selenium.webdriver.support import expected_conditions as EC
      from selenium.common.exceptions import TimeoutException,NoSuchElementException
      from selenium.webdriver import ActionChains
      from selenium.webdriver.common.keys import Keys
      from selenium.webdriver.common.by import By
      
      
      class TestDemo(unittest.TestCase):
          def setUp(self):
              self.driver = webdriver.Chrome()
      
          def test_SouhuMailSendMail(self):
              # 設定頁面加載限制時間為4秒
              self.driver.set_page_load_timeout(4)
              self.driver.maximize_window()
              try:
                  self.driver.get("http://mail.126.com")
              except TimeoutException:
                  print (u'頁面加載超過設定時間,超時')
                  self.driver.execute_script('window.stop()')
              try:
                  # 切換進frame控件
                  self.driver.switch_to.frame(self.driver.find_element_by_xpath("//iframe[contains(@id,'x-URS-iframe')]"))
                  #time.sleep(5)
                  # 用戶名
                  userName = self.driver.find_element_by_xpath("//input[@data-placeholder='郵箱帳號或手機號碼']")
                  userName.send_keys("****")
                  # 密碼
                  pwd = self.driver.find_element_by_xpath("//input[@data-placeholder='輸入密碼' and @name='password']")
                  pwd.send_keys("****")
                  # 登錄按鈕,回車代替
                  pwd.send_keys(Keys.RETURN)
                  # 顯式等待,確認頁面成功登錄并跳轉到登錄成功后的首頁
                  wait = WebDriverWait(self.driver,10)
                  wait.until(EC.element_to_be_clickable((By.XPATH,'//span[text()="寫 信"]'))) 
                  time.sleep(2)
                  self.driver.find_element_by_xpath('//span[text()="寫 信"]').click()
                  time.sleep(2)
                  # 輸入收件人
                  receiver = self.driver.find_element_by_xpath("//*[contains(@id,'_mail_emailinput')]//input")
                  receiver.send_keys("****")
                  # 輸入郵件標題
                  subject = self.driver.find_element_by_xpath('//*[contains(@id,"subjectInput")]')
                  subject.send_keys(u"這是一封測試郵件")
                  # 獲取郵件正文的富文本框
                  iframe = self.driver.find_element_by_xpath("//*[contains(@id,'editor')]//iframe")
                  self.driver.switch_to.frame(iframe)
                  editBox = self.driver.find_element_by_xpath("/html/body")
                  editBox.send_keys(u"郵件正文內容")
                  self.driver.switch_to.default_content()
                  # 點擊發送按鈕
                  self.driver.find_element_by_xpath("//span[.='發送']").click()
                  # 顯式等待發送成功元素是否出現在頁面上
                  wait.until(EC.visibility_of_element_located((By.XPATH,"//*[contains(@id,'succInfo')]")))
                  print(u"郵件發送成功")
              except TimeoutException:
                  print(u"顯式等待頁面元素超時")
              except NoSuchElementException:
                  print(u"尋找的頁面元素不存在",traceback.print_exc())
      
          def tearDown(self):
              self.driver.quit()
      
      if __name__ == '__main__':
          unittest.main()

      結果:

       

      posted @ 2020-11-11 15:05  hqq的進階日記  閱讀(500)  評論(2)    收藏  舉報
      主站蜘蛛池模板: 国产一区二区三区不卡视频| 亚洲成人av高清在线| 成人免费亚洲av在线| 三台县| 亚洲av色综合久久综合| 亚洲深夜精品在线观看| 日本视频高清一区二区三区| 无码h片在线观看网站| 国产成人精品区一区二区| 国产亚洲av日韩精品熟女| 国产一二三五区不在卡| 天海翼激烈高潮到腰振不止| 国产91精品一区二区亚洲| japan黑人极大黑炮| 日韩av影院在线观看| 九九色这里只有精品国产| 国产成人午夜福利院| 成人精品一区二区三区在线观看| 成人爽a毛片免费| bt天堂新版中文在线| 少妇午夜啪爽嗷嗷叫视频| 国产精品色哟哟成人av| 老太脱裤子让老头玩xxxxx| 国产精品成人综合色在线| 久久精品国产亚洲欧美| 国产亚洲一二三区精品| 日韩av一区二区三区不卡| 全免费A级毛片免费看无码| 国产一区二区三区不卡视频| 亚洲综合网国产精品一区| 亚洲乱码av中文一区二区| 一区二区三区黄色一级片| 日韩国产亚洲一区二区三区 | 成人福利一区二区视频在线| 激情综合五月丁香亚洲| 丰满人妻被黑人连续中出| 亚洲综合av一区二区三区| 国产av第一次处破| 高台县| 人妻系列中文字幕精品| 亚洲国产高清av网站|