【学习日志】Python selenium错误

因为有些迷茫,所以准备直接上手项目

开始学习Python web驱动测试一书,没想到一开始就发生了错误

环境是最新版的Python,Selenium,Firefox,Django等

按书上的代码敲

from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://localhost:8000')
assert 'Django' in browser.title


结果无情报错


Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
    raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver'


During handling of the above exception, another exception occurred:


Traceback (most recent call last):
  File "functional_test.py", line 2, in <module>
    browser = webdriver.Firefox()
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/webdriver.py", line 140, in __init__
    self.service.start()
  File "/usr/local/lib/python3.5/dist-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. 


Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x7f3f272d3ac8>>
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 173, in __del__
    self.stop()
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 145, in stop
    if self.process is None:


关键部分大概就是说我的什么geckodriver各种不正确

没有找到且未添加路径什么的

百度了一下发现也有很多人出现这样的问题

了解了一下大概

geckodriver是Firefox的驱动
但网上的解决办法大多是win的

stackoverflow上一个老外给出了降级的办法解决,但降级总不是好办法,于是继续寻找

综合来说解决办法为,自行安装geckodriver,并添加到相关路径


于是到github (戳这里)下载了Linux的geckodriver

然后进行相关操作

sudo tar zxvf geckodriver-v0.11.1-linux64.tar.gz #解压

sudo mv geckodriver /usr/bin/ #移动到指定路径

cd /usr/bin/                    #进入路径

sudo chmod +x geckodriver        #除去权限


之后再次测试Python代码,成功


有点小爽嘿嘿

解决办法来自http://blog.csdn.net/heybob/article/details/52922645

感谢大神


  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值