python webdriver 顯示等待-自動登入126郵箱,新增連絡人...

來源:互聯網
上載者:User

標籤:刪除線   with   tac   ali   .exe   table   使用者   arm   comm   

指令碼內容:

#encoding=utf-8
#author-夏曉旭
from selenium import webdriver
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException, NoSuchElementException
import traceback


driver=webdriver.Firefox(executable_path=‘c:\\geckodriver‘)
driver.get(‘http://mail.126.com‘)
try:
wait=WebDriverWait(driver,10,0.2)#顯示等待
driver.switch_to.frame(driver.find_element_by_xpath("//iframe[@id=‘x-URS-iframe‘]"))#切換到使用者名稱和密碼輸入框所在的frame元素

name=wait.until(lambda x:x.find_element_by_xpath("//input[@placeholder=‘郵箱帳號或手機號‘ and @name=‘email‘]"))
name.send_keys(‘xiaxiaoxu1987‘)
password=wait.until(lambda x:x.find_element_by_xpath("//input[@placeholder=‘密碼‘]"))
password.send_keys(‘gloryroad‘)
submit=wait.until(lambda x:x.find_element_by_xpath("//a[@id=‘dologin‘]"))
submit.click()
driver.switch_to.default_content()#在pycharm裡用switch_to_default_content()會被加刪除線,out了
time.sleep(5)
assert u"退出" in driver.page_source,"no exist in page_source"

address_book_link=wait.until(lambda x:x.find_element_by_xpath("//div[text()=‘通訊錄‘]"))
address_book_link.click()
#assert u"建立連絡人" in driver.page_source
add_contact_button=wait.until(lambda x:x.find_element_by_xpath("//span[text()=‘建立連絡人‘]"))
add_contact_button.click()
contact_name=wait.until(lambda x:x.find_element_by_xpath("//a[@title=‘編輯詳細姓名‘]/preceding-sibling::div/input"))
contact_name.send_keys(u"徐鳳釵")
contact_email=wait.until(lambda x:x.find_element_by_xpath("//*[@id=‘iaddress_MAIL_wrap‘]//input"))
contact_email.send_keys("[email protected]")
contact_is_star=wait.until(lambda x:x.find_element_by_xpath("//span[text()=‘設為星標連絡人‘]/preceding-sibling::span/b"))
contact_is_star.click()
contact_mobile=wait.until(lambda x:x.find_element_by_xpath("//*[@id=‘iaddress_TEL_wrap‘]//dd//input"))
contact_mobile.send_keys(‘18141134488‘)
contact_other_info=wait.until(lambda x:x.find_element_by_xpath("//textarea"))
contact_other_info.send_keys(‘my wife‘)
contact_save_button=wait.until(lambda x:x.find_element_by_xpath("//span[.=‘確 定‘]"))
contact_save_button.click()


except TimeoutException, e:
# 捕獲TimeoutException異常
print traceback.print_exc()

except NoSuchElementException, e:
# 捕獲NoSuchElementException異常
print traceback.print_exc()

except Exception, e:
# 捕獲其他異常
print traceback.print_exc()



結果:

C:\Python27\python.exe D:/test/dataDrivenTestPractice1/TestScript.py

Process finished with exit code 0



python webdriver 顯示等待-自動登入126郵箱,新增連絡人...

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.