Message: 'geckodriver' executable needs to be in PATH. 解決方法


問題描述:

執行如下代碼

# coding=utf-8
from selenium import webdriver

driver = webdriver.Firefox()
driver.maximize_window()
driver.implicitly_wait(2)

driver.get('https://www.baidu.com')
try:
    driver.find_element_by_id('kw')
    print('test pass: ID found')
except Exception as e:
    print('Exception found', format(e))

driver.quit()

提示報錯:

Traceback (most recent call last):
File "E:/PythonSelenium/CSDN/004id.py", line 4, in <module>
driver = webdriver.Firefox()
File "E:\Python35\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 142, in __init__
self.service.start()
File "E:\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

原因分析:

摘取主要報錯信息 Message: 'geckodriver' executable needs to be in PATH.

解決方法:

(1)測試環境:Selenium 3.4.0   Firefox 56.0   Python3.5.2

(2)下載火狐瀏覽器對應驅動,傳送門 https://github.com/mozilla/geckodriver/releases   結合我瀏覽器的版本需要下載V 0.19.0

(3)解壓文件獲取geckodriver.exe文件,並放置在主目錄下。重新運行后發現問題已解決。

注:注意火狐瀏覽器、Python環境變量設置。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM