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的安装路径,直接增加到 python35Libsite-packagesseleniumwebdriverfirefox 目录下的 firefox_binary.py文件中,如下图所示,然后driver = webdriver.Firefox()调用

原文地址:https://www.cnblogs.com/wangyuqin/p/6099177.html