我正在尝试使用selenium来启动谷歌浏览器但我收到错误 这是我的代码:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://localhost:8000')
assert 'Django' in browser.title
这是错误:
Traceback (most recent call last):
File "functional_tests.py", line 5, in <module>
browser = webdriver.Firefox(firefox_binary=binary)
File "C:\Python27\lib\site-
packages\selenium\webdriver\firefox\webdriver.py", line 140, in __init__
self.service.start()
File "C:\Python27\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.
Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x03D51FD0>> ignored
对此有何帮助?
答案 0 :(得分:0)
确保您拥有最新的geckodriver
,并在默认目录中安装了firefox。
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH
导致geckodriver问题,可以通过提供geckodriver的路径来解决。可能的原因,geckdriver位置未添加到PATH。
binary = FirefoxBinary('path')
browser = webdriver.Firefox(firefox_binary=binary)
Exception AttributeError: "'Service' object has no attribute 'process'"
看起来像我的firefox安装在自定义位置。请确认。