python运行时提示WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

本人亲自实践selenium + webdriver,结合了容易出现的两个问题,网上虽然有方法,但是找起来很费劲。在这里总结给大家,希望对各位有帮助!

1.python运行时提示WebDriverException:Message: 'geckodriver' executable needs to be in PATH.

解决办法:百度‘geckodriver’下载,下载32或是64位,本人的是64位的。下载完成后,将geckodriver.exe放在和python同一个目录下,我的是D:\Python27,之后再去运行

或者直接进入下载地址:https://github.com/mozilla/geckodriver/releases,根据需要自己选择

2.运行时可能会提示:

WebDriverException: Expected browser binarylocation, but unable to find binary in defaultlocation,no'moz:firefoxOptions.binary' capability provided, and no binary flagset on the command line

原因是我们安装火狐时并未安装在默认地址。这时我们需要指定Firefox浏览器程序路径。

binary =FirefoxBinary('D:\\Firefox\\Firefox\\firefox.exe')

browser =webdriver.Firefox(firefox_binary=binary)

注:提示找不到"firefoxBinary"可以通过下面语句导入    from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

3.运行时还会提示:

selenium.common.exceptions.WebDriverException: Message: Unable to find a matching set of capabilities

这是因为版本不匹配

解决方案:a.检查本机java版本,selenium3.x只支持java8版本以上,这里符合要求;

b. geckodriver版本是v0.18.1 ,firefox浏览器版本是45,卸载firefox,安装最新版本的firefox版本54;


运行脚本,可以正常执行。

猜你喜欢

转载自blog.csdn.net/weixin_37579123/article/details/60973184