您的位置:首页 > 编程语言 > Python开发

【selenium2基于Python】如何解决'geckodriver' executable needs to be in PATH.

2017-05-10 09:34 519 查看
本贴是专门用来记录学习期间遇到的问题以及解决办法的,用来帮助其他学习者,并且为自己以后解决问题累积精神力量。

内容可能比较杂,随手记,遇到一个,解决一个,就记录一个,希望对大家有点点帮助。 想了一下还是分开记录吧

如何解决’geckodriver’ executable needs to be in PATH.

# coding=utf-8
from selenium import webdriver

driver = webdriver.Firefox()
driver.get("https://www.baidu.com")

driver.find_element_by_id("kw").send_keys("selenium2")
driver.find_element_by_id("su").click()
driver.quit()


在执行第一个测试脚本:

运行时,老是报错:

Traceback (most recent call last): File

“D:\Python35\Py\BaiduLogin.py”, line 4, in

driver = webdriver.Firefox() File “D:\Python35\lib\site-packages\selenium\webdriver\firefox\webdriver.py”,

line 142, in init

self.service.start() File “D:\Python35\lib\site-packages\selenium\webdriver\common\service.py”,

line 81, in start

os.path.basename(self.path), self.start_error_message) selenium.common.exceptions.WebDriverException: Message: ‘geckodriver’ executable needs to be in PATH.

前面还有一截我就不截取了,最后发现问题在于这一句:

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

在百度的中文网页没找到答案,在Stackoverflow上面找到一个答案,但是好像还要去降pip版本,感觉不太合适。

于是在网上百度geckodriver firefox selenium,进而单独百度geckodriver才发现有人在github上发布专门的geckodriver包,各种系统版本环境下的都有。

于是下载下来,将exe执行文件解压放到python35主目录下,再运行脚本即可解决!

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐