Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 394
Sergii Sechka Avatar asked Dec 16 '20 06:12

Sergii Sechka


3 Answers

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 firefox 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:

  • SessionNotCreatedException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary'
  • InvalidArgumentException: Message: binary is not a Firefox executable error using GeckoDriver Firefox Selenium and Python
  • Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided
like image 136
undetected Selenium Avatar answered Oct 20 '22 05:10

undetected Selenium


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

like image 18
IceRevenge Avatar answered Oct 20 '22 03:10

IceRevenge


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
like image 6
crifan Avatar answered Oct 20 '22 05:10

crifan