標籤:刪除線 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郵箱,新增連絡人...