問題描述:使用selenium.webdriver時測試網頁,進行自動登入測試總是在登入成功時閃退。使用指定驅動器位置的方式chrome也會閃退
from selenium.webdriver import Chrome
web = Chrome()
web.get("http://www.chaojiying.com/user/login/")
firefox驅動下載連結:https://gitHub.com/mozilla/geckodriver/releases
火狐瀏覽器版本:101.0.1 (64 位)
火狐驅動版本:0.31.0 (2022-04-11, b617178ef491
)
嘗試使用指定火狐驅動開啟之前寫的程式,測試成功,問題還是出在了chrome瀏覽器中
from selenium.webdriver import Firefox from selenium.webdriver.common.by import By from chaojiying import Chaojiying_Client import time web = Firefox() web.get("http://www.chaojiying.com/user/login/") # 處理驗證碼 img = web.find_element(By.XPATH,'/html/body/div[3]/div/div[3]/div[1]/form/div/img').screenshot_as_png chaojiying = Chaojiying_Client('18312341234', '123456', '912345') dic = chaojiying.PostPic(img,1902) verify_code = dic['pic_str'] # 想頁面中填入使用者名稱,密碼驗證碼 web.find_element(By.XPATH,'/html/body/div[3]/div/div[3]/div[1]/form/p[1]/input').send_keys("183312341234") web.find_element(By.XPATH,'/html/body/div[3]/div/div[3]/div[1]/form/p[2]/input').send_keys("123456") web.find_element(By.XPATH,'/html/body/div[3]/div/div[3]/div[1]/form/p[3]/input').send_keys(verify_code) #點選登入 time.sleep(5) web.find_element(By.XPATH,'/html/body/div[3]/div/div[3]/div[1]/form/p[4]/input').click() # driver.quit()