安裝了python2,使用pip安裝了selenium,但是在使用時,報了“selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.”
網上查了一下解決辦法,此處做下記錄:
原因:使用pip安裝selenium,默認安裝的是最新版本的selenium,使用pip list查了一下我的selenium版本,是3.5.0的,firefox版本,是47.0.2的,selenium 3.x開始,webdriver/firefox/webdriver.py的__init__中,executable_path="geckodriver";而2.x是executable_path="wires"
方法一:可以卸載現有的selenium,安裝指定的2.X版本的selenium,這個辦法沒有試,因為就是本着selenium3來的,不打算降版本;
方法二:下載geckodriver.exe
- 下載地址:https://github.com/mozilla/geckodriver/releases,根據自己的電腦,下載的win64位的;
- 在firefox的安裝目錄下,解壓geckodriver,然后將該路徑添加到path環境變量下,不報這個錯了;
- 但是,報了一個新的錯“selenium.common.exceptions.WebDriverException: Message: Unable to find a matching set of capabilities”;
- 繼續網上查,原因是,我下載的geckodriver是V0.16.1版本的,這個版本和selenium3.4.2不兼容,需要使用deckdriverV0.15的版本;
- 重新下載了deckodriverV0.15的版本,ok了,不報這個錯了,但是,又報了一個新的錯“selenium.common.exceptions.WebDriverException: Message: Unsupported Marionette protocol version 2, required 3;
- 繼續往上查原因,說是firefox版本太低了,需要升級到最新版,ok,更新firefox,問題解決。\
- 火狐瀏覽器的安裝文件.exe也添加到path環境變量中,避免出現一些不不要的錯誤