|
本帖最后由 yyshyd 于 2016-11-30 18:21 编辑
代码
#coding=UTF-8
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.baidu.com")
driver.find_element_by_id("kw").send_keys("testing")
driver.find_element_by_id("su").click()
driver.quit()
运行时出错,如何解决?
Traceback (most recent call last):
File "C:\Python27\baidu.py", line 3, in <module>
driver = webdriver.Firefox()
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 135, in __init__
self.service.start()
File "C:\Python27\lib\site-packages\selenium\webdriver\common\service.py", line 71, in start
os.path.basename(self.path), self.start_error_message)
WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
下面是网上看的解决办法,第二和第三步看懂了试过了都没用,第一步没看懂谁能解释下
1.查看C:\Python27\Lib\site-packages\selenium\webdriver\firefox中的webdriver.py,在def_init_函数中,executable_path="geckodriver",之前搭建的环境上是executable_path="wires";
2.geckodriver是一原生态的第三方浏览器,对于selenium3.x版本都会使用geckodriver来驱动firefox,所以需要下载geckodriver.exe,下载地址:https://github.com/mozilla/geckodriver/releases
3.放在C:\Python27(查看环境变量path中是否添加C:\Python27该路径)
最终解决办法:升级火狐浏览器到最新版本
|
|