40

I must have some versions here that don't match up since I can't get Selenium with Python to fire up a Firefox web browser. I'm using an older version of Firefox because other people in here have the same old version of Python and for them the old version of Firefox works best.

Code:

from selenium import webdriver
from selenium import common
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
driver=webdriver.Firefox(capabilities=DesiredCapabilities.FIREFOX)

Error:

Traceback (most recent call last):
 File "scrapeCommunitySelenium.py", line 13, in <module>
 driver=webdriver.Firefox(capabilities=DesiredCapabilities.FIREFOX)
 File "/Library/Python/2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 158, in __init__
 keep_alive=True)
 File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
 self.start_session(desired_capabilities, browser_profile)
 File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
 response = self.execute(Command.NEW_SESSION, parameters)
 File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 311, in execute
 self.error_handler.check_response(response)
 File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
 raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities

Version info:

  • Python 2.7.10
  • Selenium 3.8.0
  • Firefox 46.0
  • GeckoDriver 0.19.1 (It's in a folder which is in my PATH environment variable)
  • MacOS 10.12.6
undetected Selenium
194k44 gold badges304 silver badges385 bronze badges
asked Dec 12, 2017 at 22:33
2
  • Are running that on Grid or locally? Commented Dec 13, 2017 at 4:55
  • Running it locally. Commented Dec 13, 2017 at 17:30

7 Answers 7

47

As you are using Selenium 3.8.0 you have to use GeckoDriver as a mandatory. But again as you are using Firefox v46.0 you have to set the capability marionette as False through DesiredCapabilities() as follows :

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
cap = DesiredCapabilities().FIREFOX
cap["marionette"] = False
browser = webdriver.Firefox(capabilities=cap, executable_path="C:\\path\\to\\geckodriver.exe")
browser.get('http://google.com/')
browser.quit()
answered Dec 13, 2017 at 4:31
3
  • 1
    ' cap["marionette"] = false ' => gives error : 'caps not defined'. What does this line change? Commented Jun 19, 2018 at 16:27
  • 3
    I keep getting "The browser appears to have exited before we could reconnect." However, its asking to close the browser each time I run the thing. Commented Dec 20, 2019 at 19:36
  • 1
    This solution also works for MacOS, just need to change the executable path. Commented Apr 29, 2020 at 13:28
16

If you're going to use Geckodriver, you definitely need to use a newer version of Firefox. Frex: https://github.com/mozilla/geckodriver/releases/tag/v0.19.0 lists FF55 or greater.

If you plan on using FF46, don't use geckodriver. Update your capabilities to have marionette set to False:

caps = DesiredCapabilities.FIREFOX.copy()
caps['marionette'] = False
driver=webdriver.Firefox(capabilities=caps)
answered Dec 13, 2017 at 2:24
1
  • 2
    Setting marionette to False seems to do the trick. Thank you! Commented Dec 13, 2017 at 17:29
6

I had this issue on my MacOS 10.5 Catalina. What I did: 1. Installed the geckodriver using brew install geckodriver 2. Deleted/uninstalled my existing(OLD) Firefox browser (v.46) and installed v70. 3. tried:

from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://google.com')

The above worked fine with no errors, by launching Firefox and loading google.com

answered Nov 24, 2019 at 7:06
2

I got this error because the Firefox browser was not installed on my machine. You can download Firefox or download the Chrome driver here. If you use the Chrome drive, make sure you add it to the path (just like the geckodriver).

And the you can use it like this:

from selenium import webdriver
driver = webdriver.Chrome()
driver.get("http://www.python.org")
answered Nov 24, 2018 at 20:38
1
  • SAME here! Wow, I must've read over 75 webpages before coming across this... Commented Nov 4, 2020 at 23:45
0

You can see similar error on Chrome as well. If you are seeing it on Ubuntu, the reason is probably you have a pre-installed version of Chrome and Firefox which is older. And you have downloaded the latest version of Chrome/Firefox driver.

Simple solution is:

  1. Uninstall the existing Chrome/Firefox browser provided from Ubuntu : Go to Applications(top left corner)->Ubuntu software center-> search Chrome and uninstall it.
  2. Install latest browser.

For Chrome, steps are as follows:

  1. wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

  2. sudo dpkg -i google-chrome-stable_current_amd64.deb

Done!

groenhen
3,01725 gold badges51 silver badges69 bronze badges
answered Jan 31, 2019 at 12:03
0

There are some possible reasons for that error like:

  1. Firefox is installed in your system
  2. Firefox access is admin only
  3. Firefox is not installed with same name
  4. Firefox version is not updated
4b0
22.4k30 gold badges97 silver badges143 bronze badges
answered Jan 31, 2020 at 7:01
0

This error can also come from the version 32bits, choose a x64 version to fix it.

answered Jun 12, 2020 at 22:38

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.