selenium3.0.1調用firefox


報錯信息如下時:

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()調用


免責聲明!

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



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