selenium使用报错“selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.”
安装了python2.7.8,使用pip安装了selenium,但是在使用时,报了“selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.”
网上查了一下解决办法,此处做下记录:
原因:驱动和firefox版本或者selenium版本不匹配
方法一:可以卸载现有的selenium,安装指定的2.X版本的selenium,这个办法没有试,因为就是本着selenium3来的,不打算降版本;
方法二:下载geckodriver.exe
- 下载地址:https://github.com/mozilla/geckodriver/releases,根据自己的电脑,下载的win64位的;
- (在firefox的安装目录下,解压geckodriver,然后将该路径添加到path环境变量下,不报这个错了;),通过查资料还有另外一种方法,直接将解压的geckodriver.exe放到python根目录下,不需要设置环境变量,我采用的是这种方法
- 到官网下载firefox的最新版本,下载时的最新版本是61.0.1(64位)
- 发现我的selenium版本低于3.1.1,于是 pip install -U selenium(升级到最新版) 升级到指定版本 pip install -U selenium==3.14.0
- 问题解决