无法找到与firefox、python、selenium(使用vagrant)匹配的功能集

无法找到与firefox、python、selenium(使用vagrant)匹配的功能集,python,selenium,firefox,vagrant,Python,Selenium,Firefox,Vagrant,使用:Selenium 3.4.3、Firefox 54、geckodriver 0.17.0 我通过尝试在使用precise64框的虚拟机上用python创建Firefox webdriver来获得此错误消息。我的笔记本电脑运行Mac OS Sierra。这是我的错误消息: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/pyt

使用:Selenium 3.4.3、Firefox 54、geckodriver 0.17.0

我通过尝试在使用precise64框的虚拟机上用python创建Firefox webdriver来获得此错误消息。我的笔记本电脑运行Mac OS Sierra。这是我的错误消息:

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 152, in __init__
    keep_alive=True)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 98, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 188, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 256, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Unable to find a matching set of capabilities
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“/usr/local/lib/python2.7/dist packages/selenium/webdriver/firefox/webdriver.py”,第152行,在__
使_保持活动状态=真)
文件“/usr/local/lib/python2.7/dist packages/selenium/webdriver/remote/webdriver.py”,第98行,在__
self.start\u会话(所需的\u功能、浏览器\u配置文件)
文件“/usr/local/lib/python2.7/dist packages/selenium/webdriver/remote/webdriver.py”,第188行,在启动会话中
响应=self.execute(Command.NEW_会话,参数)
文件“/usr/local/lib/python2.7/dist packages/selenium/webdriver/remote/webdriver.py”,执行中的第256行
self.error\u handler.check\u响应(响应)
文件“/usr/local/lib/python2.7/dist packages/selenium/webdriver/remote/errorhandler.py”,第194行,在check_响应中
引发异常类(消息、屏幕、堆栈跟踪)
selenium.common.exceptions.WebDriverException:消息:找不到匹配的功能集
我正在运行
browser=webdriver.Firefox()
。 我已尝试在我的vagrant目录中指定geckodriver可执行文件的路径,即
browser=webdriver.Firefox(“/vagrant/”)
,但仍然找不到匹配的功能集。 我的geckodriver与我尝试运行的脚本位于同一目录中。我也将流浪者文件夹添加到我的路径中。 根据我看到的各种帖子,我相信我使用的所有东西都是最新的


有人知道我为什么会遇到这个问题吗?提前谢谢。

如果其他人遇到这个问题:问题似乎是虚拟机没有显示器,或者需要像pyvirtualbox这样的虚拟显示器,或者像phantomJS这样的无头浏览器

#Code Snippet

      from selenium import webdriver
from      selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('/Applications/Firefox.app/Contents/MacOS/firefox-bin')
driver = webdriver.Firefox(executable_path = "/usr/local/bin/geckodriver")
driver.get("http://www.google.com")
print driver.title
driver.quit()
编辑: 我正在添加如何实现我列出的两个解决方案的示例。通常,解决此问题的方法取决于您有哪些限制。最简单的方法就是不使用虚拟机,但如果您确实需要使用VM,则需要采用我上面概述的两种方法之一

# PHANTOM JS SOLUTION
from selenium import webdriver
driver = webdriver.PhantomJS() # assuming your phantomJS driver is in your path already
driver.get("https://www.google.com")
driver.quit() # only use this when done with automation

# PYVIRTUALBOX SOLUTION
from pyvirtualdisplay import Display
from selenium import webdriver

display = Display(visible=0, size=(1920, 1080)).start()
driver = webdriver.Firefox()
driver.get("https://www.google.com")
display.close() # use this only once you are finished with automation
driver.quit()

不幸的是,这并没有解决问题——我仍然得到“无法找到匹配的功能集”。当我直接尝试这个方法时,我遇到了一个问题,geckodriver不在$PATH中,因此我必须使用/vagrant/文件夹中的路径,而不是/usr/local/bin/文件夹中的路径。我不确定这是否是一个单独的问题。我再试了一次,一切都成功了。如果“geckodriver”的路径正确,脚本应该可以工作。别忘了在你的可执行路径中添加“/vagrant/geckodriver”。我现在做的是:
从selenium导入webdriver
从selenium.webdriver.firefox.firefox\u binary导入FirefoxBinary
binary=FirefoxBinary('/Applications/firefox.app/Contents/MacOS/firefox bin')
从selenium.webdriver=webdriver.firefox(可执行文件路径=“/vagrant/geckodriver”)
driver.get(“http://www.google.com“
不幸的是,我仍然收到与我在原始问题中发布的相同的错误。