python:WebUI自動化測試-瀏覽器驅(qū)動

參考文章1
參考文章 2

谷歌瀏覽器驅(qū)動chromedriver:

瀏覽器和驅(qū)動:
下載地址1
下載地址 2

查看當前谷歌版本:
設置-關(guān)于 Chrome,查看當前谷歌版本

谷歌瀏覽器驅(qū)動版本不匹配(依舊能啟動):

The chromedriver version (138.0.7204.168) detected in PATH at /usr/local/bin/chromedriver might not be compatible with the detected chrome version (139.0.7258.139); currently, chromedriver 139.0.7258.138 is recommended for chrome 139.*, so it is advised to delete the driver in PATH and retry

mac下載新的與谷歌瀏覽器匹配的驅(qū)動,替換舊驅(qū)動,替換路徑:

/usr/local/bin,直接替換新的chromedriver

火狐瀏覽器驅(qū)動geckodriver:

下載地址

webUI自動化測試登錄代碼:


#coding = uft-8
import  time
from selenium import webdriver
from selenium.webdriver.common.by import By

"""
做自動化測試
1.打開瀏覽器
2.訪問登錄網(wǎng)址
3.輸入用戶名
4.輸入密碼
5.點擊登錄
"""

# 1.打開瀏覽器
driver = webdriver.Chrome()
# 2.訪問登錄網(wǎng)址
driver.get("http://novel.hctestedu.com/user/login.html")
time.sleep(3)
# 3.輸入用戶名
driver.find_element(By.NAME, "txtUName").send_keys("15574113907")
time.sleep(3)
# 4.輸入密碼
driver.find_element(By.XPATH, "http://*[@id='txtPassword']").send_keys("123456")
# driver.find_element(By.NAME, "txtPassword").send_keys("123456")
time.sleep(3)
# 5.點擊登錄
driver.find_element(By.NAME, "btnLogin").click()
time.sleep(5)
driver.quit()


?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容