報錯信息如下時:
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
這是因為在Firefox高版本需要使用 geckodriver 來驅動,不再使用Seleniu默認自帶的Firefox webdriver。
我們只需要在下面這個地址下載 geckodriver 並將 其所在的路徑設為環境變量即可解決。
https://github.com/mozilla/geckodriver/releases
當報如下錯誤信息時,則是
selenium.common.exceptions.WebDriverException: Message: Expected browser binary location, but unable to find binary in default location,
no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line
這時我們需要指定Firefox瀏覽器程序路徑。
binary = FirefoxBinary('D:\\Firefox\\Firefox\\firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary)
注:提示找不到"firefoxBinary"可以通過下面語句導入 from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
這樣就能正常使用了。
另一個處理辦法是將firefox的安裝路徑,直接增加到 python35\Lib\site-packages\selenium\webdriver\firefox 目錄下的 firefox_binary.py文件中,如下圖所示,然后driver = webdriver.Firefox()調用