3

Using: Selenium 3.4.3, Firefox 54, geckodriver 0.17.0

I am getting this error message by trying to create a Firefox webdriver in python, on my virtual machine which is using the precise64 box. My laptop is running Mac OS Sierra. This is my error message:

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

I'm running browser = webdriver.Firefox(). I have tried specifying the path to the geckodriver executable in my vagrant directory, i.e. browser = webdriver.Firefox('/vagrant/'), but it is still unable to find a matching set of capabilities. My geckodriver is in the same directory as the script I'm trying to run. I have added the vagrant folder to my path as well. I believe everything I'm using is up to date, according to the various posts I've seen like this one.

Does anyone know why I could be getting this issue? Thank you in advance.

2 Answers2

2

In case anyone else gets this problem: the problem appears to be that virtual machines don't have a display, and either need a virtual display like pyvirtualbox or a headless browser like phantomJS.

EDIT: I'm adding examples of how to implement the two solutions I listed. In general, the approach you take to solve this problem depends on what restrictions you have. The easiest approach is to just not use a virtual machine, but if you do need to use a VM you'll need to take one of the two approaches I outlined above.

# 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()
0
#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()
Monika
  • 714
  • 1
  • 4
  • 10
  • Unfortunately this did not solve the issue - I'm still getting the "Unable to find a matching set of capabilities". When I directly tried this, I got an issue where the geckodriver was not in the $PATH, so I had to use a path from the /vagrant/ folder, **not** the /usr/local/bin/ folder. I'm not sure if that's a separate issue. – R Balasubramanian Jun 27 '17 at 22:59
  • I tried again and everything worked. Your script should work if the path of "geckodriver" is correct. Don't forget to add "/vagrant/geckodriver" in your executable_path. – Monika Jun 28 '17 at 03:11
  • Here's what I am doing: `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")` I'm still getting the same error that I posted in the original question, unfortunately. – R Balasubramanian Jun 28 '17 at 14:34