筆者運作代碼使用selenium的隐式等待時出現報錯:
1 from selenium import webdriver # 從selenium導入webdriver
2 import time
3 driver = webdriver.Chrome()
4 driver.get('https://www.baidu.com') # 擷取百度頁面
5 driver.implicitly_wait(3)
6 inputElement = driver.find_element_by_id('kw').send_keys(u"隐式等待") #擷取輸入框
7 driver.implicitly_wait(3)
8 searchButton = driver.find_element_by_id('su').click() #擷取搜尋按鈕
9 time.sleep(3)
10 driver.quit()
錯誤:
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIn5GcuITMzcTO2YzNx0SM0QTOyMTN0ETOxcDM5EDMy0COxcTNxATMvw1NwkTMwIzLchTM3UTMwEzLcd2bsJ2Lc12bj5ycn9Gbi52YugTMwIzZtl2Lc9CX6MHc0RHaiojIsJye.png)
由于已經查驗過不是chrome.driver版本與chrome浏覽器的版本不比對的問題,是以筆者想到是不是selenium版本問題導緻,筆者目前的selenium版本是selenium-3.5.0,解除安裝selenium-3.5.0,重新下載下傳 selenium-3.141.0(pip install selenium==3.141.0)之後,運作程式,問題解決。
Sic Parvis Magna