Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided using GeckoDriver
Asked Answered
C

11

44
from selenium import webdriver;
browser= webdriver.Firefox();
browser.get('http://www.seleniumhq.org');

When I try to run this code, it gives me an error message:

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.

Any thoughts-highly appreciated!

Chrisoula answered 16/12, 2020 at 6:35 Comment(2)
You need put the webdriver for firefox in you script director or system path. link: <github.com/mozilla/geckodriver/releases>Vizor
Please find the below link to get the answer https://mcmap.net/q/374990/-notadirectoryerror-winerror-267-the-directory-name-is-invalid-error-while-invoking-firefox-through-selenium-pythonIlan
F
77

This error message...

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.

...implies that the GeckoDriver was unable to find the Firefox binary at the default location. Additionally you haven't passed the moz:firefoxOptions.binary capability.


Solution

Possibly within your system is installed in a custom location and these cases you need to pass the absolute path of the Firefox binary through the moz:firefoxOptions.binary capability as follows:

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/')

References

You can find a couple of relevant detailed discussion in:

Frenchy answered 16/12, 2020 at 11:24 Comment(1)
I had to restart RIDE for it to see this change after installing firefoxLogrolling
L
27

Firefox was not installed on my system at all. That's why this error came up.

Leupold answered 7/5, 2021 at 15:52 Comment(0)
K
10

same issue here:

  • Environment
    • OS: Mac
      • Not install Firefox application
      • has installed geckodriver, can found in PATH
  • Error Reason: Not installed Firefox
  • Solution: (goto firefox official site to download and) install Firefox
Killian answered 18/7, 2021 at 4:32 Comment(0)
S
4

I have uninstalled firefox and installed it again which resolved my issue.

Simonette answered 21/4, 2021 at 9:28 Comment(0)
S
4

Before this ensure that path variable has include for geckodriver click here to download driver and run below python script.

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(options=options)
driver.get('http://google.com/')
Singlephase answered 11/11, 2021 at 12:4 Comment(0)
C
0

You should download appropriate web driver from https://github.com/mozilla/geckodriver/releases and put it into folder where your py file is. Also you can put it anywhere as long as the location of the file it is in your system path.

Calpac answered 16/12, 2020 at 6:42 Comment(0)
H
0

Selenium uses a web driver (a specific one for each web browser) in order to communicate with the browser installed on your system (Firefox in your case).

To use Firefox, you have to:

  1. Download its web driver from https://github.com/mozilla/geckodriver/releases
  2. Put the web driver in a specific location in the file system (same folder as the python script for example)
  3. Add the web driver location path when initializing in the python code.

So the final code would look like this:

from selenium import webdriver

browser = webdriver.Firefox('./geckodriver')

browser.get('https://www.python.org/')

Note: Sometimes a newer version of the web driver isn't compatible with an older version of the browser installed on your system.

Hypoplasia answered 16/12, 2020 at 7:34 Comment(0)
S
0

I have encountered the same problem (Windows, Firefox v99, Selenium 4.1.4, geckodriver 0.31.0), the path to exe file and the driver initialisation were set correctly, solved the issue by changing the win32 by win64 version of geckodriver

Sequent answered 4/5, 2022 at 10:34 Comment(0)
M
0

as a side note for selenium/firefox (but with C#, not Python), this issue is quite relevant now in the sense that firefox location looks to be stored in windows in a new regedit location. Indeed geckodriver is looking in regedit location documented here:

HKEY_LOCAL_MACHINE\SOFTWARE WOW6432Node\Mozilla\Mozilla Firefox\[VERSION]\Main\PathToExe


HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Firefox\[VERSION]\Main\PathToExe

Source: https://developer.mozilla.org/en-US/docs/Web/WebDriver/Capabilities/firefoxOptions

when on my machine it is there:

HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Firefox 109.0\bin

With the version number stored here:

HKEY_LOCAL_MACHINE\SOFTWARE\mozilla.org\Mozilla

and I set the selenium driver with C# Api with (path hardcoded for the poc):

var options = new FirefoxOptions();
...
options.BrowserExecutableLocation = @"C:\Program Files\Mozilla Firefox\firefox.exe";
Driver = new FirefoxDriver(options);

Regards

Meroblastic answered 30/1, 2023 at 15:40 Comment(0)
V
0

check whether firefox is installed in your system

firefox -v

if not, install using snap

sudo snap install firefox
Visitation answered 4/8, 2023 at 6:53 Comment(0)
M
-1

You need to download geckodriver.

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

from selenium import webdriver;

browser= webdriver.Firefox('./geckodriver');
browser.get('http://www.seleniumhq.org');
Montagna answered 16/12, 2020 at 6:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.