47

I'm trying to follow a tutorial about Selenium, http://selenium-python.readthedocs.io/getting-started.html. I've downloaded the latest version of geckodriver and copied it to /usr/local/bin. However, when I try

from selenium import webdriver
driver = webdriver.Firefox()

I get the following error message:

Traceback (most recent call last):
  File "/Users/kurtpeek/Documents/Scratch/selenium_getting_started.py", line 4, in <module>
    driver = webdriver.Firefox()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 152, in __init__
    keep_alive=True)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 98, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 188, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in execute
    self.error_handler.check_response(response)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-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

[Finished in 1.2s with exit code 1]

From https://github.com/SeleniumHQ/selenium/issues/3884, it seems like other users are experiencing similar issues, but the Selenium team is unable to reproduce it. How can I get Selenium working with Firefox? (It does work with chromedriver and a webdriver.Chrome() instance, so I suspect this might be a bug in Selenium).

Kurt Peek
  • 52,165
  • 91
  • 301
  • 526

11 Answers11

32

Updating Firefox and Selenium solved it for me. I don't pretend to have an explanation for the root cause however.

  • Updated Firefox 48 → 53
  • Updated to Selenium 3.4.1

I also reinstalled/updated Geckodriver using Homebrew and explicitly used it as an executable for Selenium WebDriver, but it turned out that it wasn't necessary to mitigate the "Unable to find matching set of capabilities" error.

Hien Nguyen
  • 24,551
  • 7
  • 52
  • 62
P A N
  • 5,642
  • 15
  • 52
  • 103
  • 1
    Also, in my case. "sudo ln -s /usr/bin/firefox-developer-edition /usr/bin/firefox" fixed things. ;-) – Ubuntourist Feb 17 '20 at 14:26
  • As @Ubuntourist says: make sure the Firefox executable is in your `PATH`. This is especially important if you're running a nightly or developer version not installed through the package manager. – jnns Mar 19 '20 at 10:17
9

I had this same issue, and the problem was related to using Firefox ESR (I'm on Debian). To be more specific, I'm on Debian 10 using 64-bit Firefox 68.11.0esr, python3.7, selenium 3.141.0, and geckodriver 0.27.0.

Here's the standard example I used that failed:

from selenium import webdriver

browser = webdriver.Firefox()
browser.get("http://google.com")

As recommended in this answer, I changed:

browser = webdriver.Firefox()

to

browser = webdriver.Firefox(firefox_binary="/usr/bin/firefox-esr")

and it worked.

If you don't know the path to firefox-esr, you can run sudo find / -name firefox-esr on the command line. Several should come up.

kdwarn
  • 313
  • 5
  • 7
8

for me it was enough to just upgrade FF

elad silver
  • 9,222
  • 4
  • 43
  • 67
  • 1
    Updating firefox fixed this problem for me too. Go to Help>About Firefox and it will automatically start updating the firefox browser. Restart browser when the update is finished. – kraftwerk Aug 28 '17 at 01:40
  • 1
    I am using Firefox 61.0.2 (64-bit) ,windows10 ,python 3.5 ,selenium3.14 but i am getting the error selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities – SecureTech Aug 21 '18 at 17:59
5

Mac user here.

I fixed this issue by making sure Firefox is named "Firefox" and in the "Applications" folder. I had called it "Firefox 58" before (I have multiple versions).

Jeremy S.
  • 1,086
  • 8
  • 18
3

Just sharing my success case here

Note: Remember the Architecture matters here, Window 64/32 or Linux 64/32. Make sure you download the right 64/32 bit Selenium Webdriver, 64/32 Geckodriver.

My configuration was as follows:

Linux: Centos 7 64bit, Window 7 64bit

Firefox: 52.0.3

Selenium Webdriver: 3.4.0 (Windows), 3.8.1 (Linux Centos)

GeckoDriver: v0.16.0 (Windows), v0.17.0 (Linux Centos)

Working Code (Without Proxy Settings)

System.setProperty("webdriver.gecko.driver", "/home/seleniumproject/geckodrivers/linux/v0.17/geckodriver");

ProfilesIni ini = new ProfilesIni();


// Change the profile name to your own. The profile name can 
// be found under .mozilla folder ~/.mozilla/firefox/profile. 
// See you profile.ini for the default profile name

FirefoxProfile profile = ini.getProfile("default"); 

DesiredCapabilities cap = new DesiredCapabilities();
cap.setAcceptInsecureCerts(true);

FirefoxBinary firefoxBinary = new FirefoxBinary();

GeckoDriverService service =new GeckoDriverService.Builder(firefoxBinary)
        .usingDriverExecutable(new File("/home/seleniumproject/geckodrivers/linux/v0.17/geckodriver"))
        .usingAnyFreePort()
        .build();
try {
    service.start();
} catch (IOException e) {
    e.printStackTrace();
}

FirefoxOptions options = new FirefoxOptions().setBinary(firefoxBinary).setProfile(profile).addCapabilities(cap);

driver = new FirefoxDriver(options);
driver.get("https://www.google.com");

System.out.println("Life Title -> " + driver.getTitle());
driver.close();

Working Code (With Proxy Settings)

    System.setProperty("webdriver.gecko.driver", "/home/seleniumproject/geckodrivers/linux/v0.17/geckodriver");

    String PROXY = "my-proxy.co.jp";
    int PORT = 8301;


    ProfilesIni ini = new ProfilesIni();


    // Change the profile name to your own. The profile name can 
    // be found under .mozilla folder ~/.mozilla/firefox/profile. 
    // See you profile.ini for the default profile name

    FirefoxProfile profile = ini.getProfile("default"); 


    com.google.gson.JsonObject json = new com.google.gson.JsonObject();
    json.addProperty("proxyType", "manual");
    json.addProperty("httpProxy", PROXY);
    json.addProperty("httpProxyPort", PORT);
    json.addProperty("sslProxy", PROXY);
    json.addProperty("sslProxyPort", PORT);

    DesiredCapabilities cap = new DesiredCapabilities();
    cap.setAcceptInsecureCerts(true);
    cap.setCapability("proxy", json);


    FirefoxBinary firefoxBinary = new FirefoxBinary();

    GeckoDriverService service =new GeckoDriverService.Builder(firefoxBinary)
            .usingDriverExecutable(new File("/home/seleniumproject/geckodrivers/linux/v0.17/geckodriver"))
            .usingAnyFreePort()
            .usingAnyFreePort()
            .build();
    try {
        service.start();
    } catch (IOException e) {
        e.printStackTrace();
    }

    FirefoxOptions options = new FirefoxOptions().setBinary(firefoxBinary).setProfile(profile).addCapabilities(cap);

    driver = new FirefoxDriver(options);
    driver.get("https://www.google.com");

    System.out.println("Life Title -> " + driver.getTitle());
    driver.close();
jww
  • 97,681
  • 90
  • 411
  • 885
HA S
  • 1,129
  • 12
  • 10
  • can u help me out??? im struggling to set up selenium in the VPS i just purchased so that i could do precisely this. [first tried with chrome, but still running into an issue after hours of troubleshooting.](https://stackoverflow.com/questions/50997096/selenium-chrome-chromedriver-issue-preventing-crawl-on-vps-devtoolsactiveport-f) so now decided to try firefox but getting a different error that reads: `selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities` – oldboy Jun 23 '18 at 04:59
  • Seems like mis-match between Firefox and GeckoDriver. Could give me detials about Firefox version, Geckodriver and Selenium Version ? – HA S Jun 27 '18 at 05:58
  • i got it working!! not sure why it was throwing that error tho – oldboy Jun 27 '18 at 05:59
  • Good to know ! 7:) – HA S Jun 27 '18 at 06:07
3

In my case, I only have Firefox Developer Edition but still throw same error.

After installing a standard Firefox version, it solves.

Hongbo Miao
  • 45,290
  • 60
  • 174
  • 267
  • The issue is not about Firefox Developer Edition itself, it's about the name it has. If you rename that version from `Firefox Developer Edition` to `Firefox` it should be fine. – Mauricio May 27 '20 at 07:27
2

I had the same issue. My geckodriver was 32 bit and fireFox was 64. Resolved by updating geckodriver to 64 bit.

Joe12
  • 69
  • 1
  • 12
2

I had exactly the same issue when i was using selenium firefox()

>> webdriver.Firefox()

it was not working : throwing error like "Unable to find a matching set of capabilities"

Then i installed geckodriver.exe and that put that .exe file inside the both directory

C:\Users\<USER-NAME>\AppData\Local\Programs\Python\Python36\Scripts

and

C:\Users\<USER-NAME>\AppData\Local\Programs\Python\Python36\

and set these two paths in the environment setting

then it started working

Priyansh gupta
  • 906
  • 12
  • 10
1

Here's the solution that solved it for me. Don't overlook this point: make sure you're using the correct 32/64 bit version of the binaries - it should be uniform - e.g. if the firefox is 64bit, so must be the geckodriver.

AzyCrw4282
  • 7,222
  • 5
  • 19
  • 35
0

Got the same error on a droplet at DigitalOcean - FireFox was not installed . Stack trace of error was as seen below -

exception_class 
<class 'selenium.common.exceptions.SessionNotCreatedException'>
json    
<module 'json' from '/usr/lib/python3.5/json/__init__.py'>
message 
'Unable to find a matching set of capabilities'
response    
{'status': 500,
 'value': '{"value":{"error":"session not created","message":"Unable to find a '
          'matching set of capabilities","stacktrace":""}}'}
screen  
None
self    
<selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x7f428e3f10f0>
stacktrace  
None
status  
'session not created'
value   
{'error': 'session not created',
 'message': 'Unable to find a matching set of capabilities',
 'stacktrace': ''}
value_json  
('{"value":{"error":"session not created","message":"Unable to find a matching '
 'set of capabilities","stacktrace":""}}')
Rohit Dhankar
  • 1,574
  • 18
  • 25
0

It seems like different workarounds are seem to make the error go away. After ensuring you have downloaded and installed the 64bit versions for Firefox and geckodriver.exe, update the PATH with the location of the geckodriver.exe. What may also help before running the script, launch the geckodriver.exe which opens a cmd like window. Now if you run the py script, you shouldn't run into the error below:

selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities
joiner
  • 47
  • 1
  • 2
  • 11