Selenium+Python 使用send_keys報錯

問題背景:

使用基於Python的Selenium自動化測試,代碼如下:

from selenium import webdriver

driver = webdriver.Chrome()

driver.get("https://www.baidu.com/")
driver.find_element_by_id("kw").send_keys("2020")

運行報錯如下:
在這裏插入圖片描述在這裏插入圖片描述

File "D:/PythonWorkSpace/AutomaticTesting/Demo.py", line 8, in <module>
    driver.find_element_by_id("kw").send_keys("2020")
selenium.common.exceptions.WebDriverException: Message: unknown error: call function result missing 'value'

解決方案:

百度查到的都是說

(1)chromedriver要和所使用的Chrome版本匹配
chromedriver下載:https://npm.taobao.org/mirrors/chromedriver/
(2)把chromedriver.exe放在python安裝目錄下,如D:\Python36

實際上,親測有效的方案是

把chromedriver.exe
windows 下,放在C:\Windows\System32目錄下;
Linux下,把下載好的文件放在 /usr/bin 目錄下;
在這裏插入圖片描述
參考:https://www.cnblogs.com/lizm166/p/9983203.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章