Solving Selenium error – Unable to find a matching set of capabilities

Solving Selenium error – Unable to find a matching set of capabilities is an error which occurs in Selenium when you have a faulty installation or for many other reasons.

In this article I am going to explain what happens when you get this error and how you can solve it with a main solution, we will also explore other solutions which can possibly solve the issue.

Explaining the Error : Selenium error – Unable to find a matching set of capabilities

This is a python error which occurs in Selenium when you have a faulty installation or for many other reasons.

The error can happen even after running a simple Selenium script like this one.

                                                                       #
from selenium import webdriver
browser = webdriver.Firefox()
browser.get("http://twitter.com")
                                                                       #

The error message should look like the error in the example bellow, make sure you have a similar error message in order to avoid confusion.

                                                                       #
    driver = webdriver.Firefox()
    keep_alive=True)
    self.start_session(desired_capabilities, browser_profile)
    response = self.execute(Command.NEW_SESSION, parameters)
.....
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Unable to
 find a matching set of capabilities
                                                                       #

Solution 1 : Add Firefox executable to your PATH and upgrade Selenium and Firefox

The first solution should be enough to solve the problem for most people. First, we should understand that adding the Firefox executable to your PATH is very important . This will fix your issue and prevent other issues and conflicts in the future.

You can add the Firefox executable to your PATH using this command.

                                                                       #
sudo ln -s /usr/bin/firefox-developer-edition /usr/bin/firefox
                                                                       #

That was the first step, the second step is to upgrade both Firefox and Selenium.

You can upgrade Firefox manually and without using any commands, so start with upgrading Firefox.

Finally, upgrade selenium using the command bellow. Selenium 4.4.3 is the latest release as of this date.

                                                                       #
pip install selenium==4.4.3
                                                                       #

Keep in mind that Selenium 4 will require a minimum Python 3.7 or higher.

I hope the solution above has been helpful, if not try the second and last solution.

Solution 2 : use firefox-esr (use Firefox ESR)

First, you should install Firefox ESR, after the installation is done. Run the command bellow and copy the path of Firefox ESR.

                                                                       #
sudo find / -name firefox-esr
                                                                       #

Now, in your selenium code you should replace the line browser = webdriver.Firefox() with the line bellow.

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

Where firefox_binary=”/usr/bin/firefox-esr is the path to firefox-esr in my case.

After these steps, your Selenium code should run with no issues and no problems.

Summing-up

This is the end of the article, the error could be confusing but with a little bit of investigating the error could be solved, thanks for reading our post and good luck with the scripts to come.

If you want to support us consider donating to our Kofi account using the red button on top of this page. Keep coding, keep learning Python and cheers.

If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/