代码之家  ›  专栏  ›  技术社区  ›  R Balasubramanian

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

  •  3
  • R Balasubramanian  · 技术社区  · 7 年前

    使用: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
    

    我在跑步 browser = webdriver.Firefox() 我已经尝试在我的 目录,即。 browser = webdriver.Firefox('/vagrant/') 我的geckodriver与我尝试运行的脚本位于同一目录中。我也将流浪者文件夹添加到我的路径中。 根据我看到的各种帖子,我相信我正在使用的一切都是最新的 this one

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

    2 回复  |  直到 7 年前
        1
  •  2
  •   R Balasubramanian    7 年前

    如果其他人遇到这个问题:问题似乎是虚拟机没有显示器,需要像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()
    
        2
  •  0
  •   Monika    7 年前
    #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()