自動化測試指令碼 測試百度搜尋Selenium

2021-10-09 11:26:40 字數 1283 閱讀 4624

自動化測試指令碼

測試用例

測試步驟:

1)啟動瀏覽器

3)定位搜尋輸入框,記錄下輸入框元素的xpath表示式://*[@id=『kw』]

6)在搜尋結果列表去判斷是否存在知乎官網這個鏈結

7)退出瀏覽器,結束測試

測試指令碼:

import time

from selenium import webdriver

//開啟chrome,如果用firefox,換成webdriver.firefox()

driver = webdriver.chrome()

//最大化瀏覽器視窗

driver.maximize_window()

//設定隱式時間等待

driver.implicitly_wait(8)

driver.get(「

//搜尋輸入框輸入selenium

driver.find_element_by_id(「kw」).send_keys(「selenium」)

或者driver.find_element_by_xpath("//*[@id=『kw』]").send_keys(「selenium」)

driver.find_element_by_id(「su」).click()

或者driver.find_element_by_xpath("//*[@id=『su』]").click()

//匯入time模組,等待2秒

time.sleep(2)

這裡通過元素xpath表示式來確定該元素顯示在結果列表,從而判斷selenium官網這個鏈結顯示在結果列表。

定義變數ele_string,判斷是否是搜尋後需要顯示的值

ele_string=driver.find_element_by_xpath("//*[@id=『1』]/h3/a").text

if(ele_string ==「selenium - web browser automation」):

print(「測試成功」)

selenium練習三 百度搜尋自動化指令碼

自動化指令碼的功能要求 訪問 後,回退到搜尋的結果頁面。coding cp936 從匯入selenium中匯入webdriver from selenium import webdriver import time 以火狐瀏覽器開啟 wd webdriver.firefox 輸入 wd.get ti...

測試360 google 百度搜尋

圖 openstack中國行 深圳站 在3wcoffee舉行 圖 cosug社群負責人,sae技術經理 程輝 圖 香港數碼港雲計算工程師 駱文鐘bruce 駱文鐘負責香港數碼港科技中心openstack iaas公有雲平台開發和運營,目前其已經投入生產環境使用。bruce亦積極將開源雲軟體opens...

定位操作封裝!百度搜尋測試 測試用例 測試套件

資料夾 fz 檔名 fengzhuang.py from selenium import webdriver import time class commom object def init self self.driver webdriver.chrome self.driver.implicit...