selenium使用报错“selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.”

安装了python3,使用pip安装了selenium,但是在使用时,报了“selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.”

网上查了一下解决办法,此处做下记录:

原因:使用pip安装selenium,默认安装的是最新版本的selenium,使用pip list查了一下我的selenium版本,是3.4.2的,firefox版本,是43.0.1的,selenium 3.x开始,webdriver/firefox/webdriver.py的__init__中,executable_path="geckodriver";而2.x是executable_path="wires"

方法一:可以卸载现有的selenium,安装指定的2.X版本的selenium,这个办法没有试,因为就是本着selenium3来的,不打算降版本;

方法二:下载geckodriver.exe

  1. 下载地址:https://github.com/mozilla/geckodriver/releases,根据自己的电脑,下载的win64位的;
  2. 在firefox的安装目录下,解压geckodriver,然后将该路径添加到path环境变量下,不报这个错了;
  3. 但是,报了一个新的错“selenium.common.exceptions.WebDriverException: Message: Unable to find a matching set of capabilities”;
  4. 继续网上查,原因是,我下载的geckodriver是V0.16.1版本的,这个版本和selenium3.4.2不兼容,需要使用deckdriverV0.15的版本;
  5. 重新下载了deckodriverV0.15的版本,ok了,不报这个错了,但是,又报了一个新的错“selenium.common.exceptions.WebDriverException: Message: Unsupported Marionette protocol version 2, required 3;
  6. 继续往上查原因,说是firefox版本太低了,需要升级到最新版,ok,更新firefox,问题解决。
原文地址:https://www.cnblogs.com/yousuosiyss/p/6882420.html