Solving GeckoDriver Error – Expected browser binary location, but unable to find binary in default location, no ‘moz:firefoxOptions.binary’ capability provided

Expected browser binary location, but unable to find binary in default location, no ‘moz:firefoxOptions.binary’ capability provided is an error which occurs when GeckoDriver is unable to find the Firefox binary at the default location.

In this article I am going to help you solve this error and understand the root of the problem, also I am presenting other possible solutions that may work if the main solution does not work for you.

Exploring the Error : Expected browser binary location, but unable to find binary in default location, no ‘moz:firefoxOptions.binary’ capability provided

First of all we need to understand how the message of the error looks like, make sure your error message matches this error message to avoid any kind of confusion.

                                                                       #
Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line.
                                                                       #

Bellow is a number of tested solutions that I have tried and that have worked for me.

Solution 1 : actually install firefox

The code that you can use to reproduce the error is simple. The example bellow will produce the error.

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

We are just trying to access google.com on the Firefox browser.

For many people, the error happens because they have not installed Firefox on their machines.

The solution is to simply download and install Firefox from the official Firefox website.

You can also try the solution bellow if this one does not solve the issue.

Solution 2 : install geckodriver

If the solutions above did not work, try this one.

The issue might be that you do not have geckodriver installed on your machine.

Navigate to the link bellow, then download it.

                                                                       #
https://github.com/mozilla/geckodriver/releases
                                                                       #

Then put it into the folder where your have the py file. As long as the location of the file is in your system path then you can put the file anywhere.

If this solution does not work, try the solution bellow.

Solution 3 : pass the path of the Firefox binary

Another solution is to run the following command

If you chose a custom location of your firefox installation you should pass the path of the Firefox binary through the moz:firefoxOptions.binary capability.

Bellow is the code that will help you achieve your goal.

                                                                       #
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.binary_location = r'C:\Program Files\Mozilla Firefox\firefox.exe'
driver = webdriver.Firefox(executable_path=r'C:\WebDrivers\geckodriver.exe', options=options)
driver.get('http://google.com/')
                                                                       #

I hope this guide and our solutions have helped you solve your problem, thank you for reading.

Summing-up

This is the end of our article, I hope the solutions I presented worked for you, Learning Python is a fun journey, do not let the errors discourage you.

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