代码:
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:
原因:
未找到firefox浏览器驱动 geckodriver
解决:
下载了Linux的geckodriver
下载地址:https://github.com/mozilla/geckodriver/releases
然后安装
sudo tar zxvf geckodriver-v0.11.1-linux64.tar.gz
sudo mv geckodriver /usr/bin/
sudo chmod +x /usr/bin/geckodriver
再次测试成功
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。