selenium运行时出现错误信息:Message: ‘geckodriver‘ executable needs to be in PATH 的解决办法

本文解决在Python+Selenium环境中使用Firefox时遇到的'geckodriver'未找到的问题,详细步骤包括下载geckodriver、配置环境变量及放置在Python目录下。

webdriver error: 'geckodriver' executable needs to be in PATH.

 
 
楼主#
更多发布于:2018-01-23 13:06
 
 
在使用python + selenium 搭建环境时: 

运行如下代码: 

from selenium import webdriver 

from selenium.common.exceptions import NoSuchElementException 
from selenium.webdriver.common.keys import Keys 
# webdriver.Firefox() 找firefox 默认安装 路径 
driver = webdriver.Firefox() 
driver.get('http://baidu.com') 

在运行过程中报错,提示信息如下: 

selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 

原因: 在selenium 3中使用webdriver.Firefox() , 如果下载geckodriver.exe 

解决方案: 

1.  下载geckodriver.exe , 下载地址:https://github.com/mozilla/geckodriver/releases 

2. 下载后,将geckodriver.exe复制到Firefox 浏览器的安装目录. 一般默认路径在:C:\Program Files (x86)\mozilla firefox目录下; 
3. 将FireFox 的路径添加到环境变量Path中添加路径:如,C:\Program Files (x86)\mozilla firefox; 
4. 将geckodriver.exe ,放到python 的目录下,如下: 
    


注:如何还要报错,如下以下提示: 

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


 
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值