以下是我所处的环境: Linux goorm 4.4.0-116-generic#140-Ubuntu SMP Mon Feb 12 21:23:04 UTC 2018 x86_64 x86_64 x86_64 GNU / Linux
Selenium(3.10),geckodriver(0.19.1),Firefox58(我想要无头版本,所以我不认为这很重要)
>>> from selenium import webdriver
>>> from selenium.webdriver.firefox.options import Options
>>> options = Options()
>>> options.add_argument("--headless")
>>> driver = webdriver.Firefox(firefox_options=options)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 162, in __init__keep_alive=True)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 154, in__init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 243, instart_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 312, inexecute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242,in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities
geckodriver位于/ usr / local / bin目录中。我都尝试过,有没有专门给出executable_path参数,它会产生相同的错误。 如何删除上述错误并让Firefox()与Selenium一起使用?
答案 0 :(得分:0)
由于可以在本网站的几个问题中找到,因此您应确保已完成以下操作:
export PATH=$PATH:/path/to/geckodriver
如果问题仍然存在,您可能需要更新geckodriver和/或Firefox。
答案 1 :(得分:0)
使用 Selenium v3.x , GeckoDriver 和 Firefox浏览器时,您可能需要传递参数 executable_path 以及 GeckoDriver 二进制文件的绝对路径以及以下选项:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.add_argument("--headless")
options.addArguments("start-maximized");
options.addArguments("--disable-gpu");
options.addArguments("--disable-extensions");
driver = webdriver.Firefox(firefox_options=options, executable_path='/usr/local/bin/geckodriver')