【问题标题】:Unable to find a matching set of capabilities with firefox, python, selenium (using vagrant)无法找到与 firefox、python、selenium 匹配的一组功能(使用 vagrant)
【发布时间】:2017-11-30 21:39:40
【问题描述】:

使用:Selenium 3.4.3、Firefox 54、geckodriver 0.17.0

我通过尝试在 python 中创建一个 Firefox 网络驱动程序,在我使用精确 64 框的虚拟机上收到此错误消息。我的笔记本电脑正在运行 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

我正在运行browser = webdriver.Firefox()。 我尝试在我的 vagrant 目录中指定 geckodriver 可执行文件的路径,即browser = webdriver.Firefox('/vagrant/'),但它仍然无法找到匹配的功能集。 我的 geckodriver 与我尝试运行的脚本位于同一目录中。我也将 vagrant 文件夹添加到我的路径中。 我相信我使用的所有东西都是最新的,根据我看到的各种帖子,比如this one

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

【问题讨论】:

    标签: python selenium firefox vagrant


    【解决方案1】:
    #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()
    

    【讨论】:

    • 不幸的是,这并没有解决问题 - 我仍然收到“无法找到一组匹配的功能”。当我直接尝试这个时,我遇到了一个问题,即 geckodriver 不在 $PATH 中,所以我不得不使用 /vagrant/ 文件夹中的路径,不是 /usr/local/bin/文件夹。我不确定这是否是一个单独的问题。
    • 我又试了一次,一切正常。如果“geckodriver”的路径正确,您的脚本应该可以工作。不要忘记在您的可执行文件路径中添加“/vagrant/geckodriver”。
    • 这就是我正在做的事情: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="/vagrant/geckodriver") driver.get("http://www.google.com") 不幸的是,我仍然遇到我在原始问题中发布的相同错误。
    【解决方案2】:

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

    编辑: 我正在添加如何实施我列出的两个解决方案的示例。一般来说,解决这个问题的方法取决于你有什么限制。最简单的方法是不使用虚拟机,但如果您确实需要使用 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()
    

    【讨论】:

      猜你喜欢
      • 2018-08-27
      • 2019-01-30
      • 2018-05-26
      • 2018-07-30
      • 2020-07-30
      • 2020-04-28
      • 2017-11-19
      • 2018-12-31
      相关资源
      最近更新 更多