Skip to content
Advertisement

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

I am trying to get back into using Python Webdriver. I have here the code

from selenium import webdriver
driver = webdriver.Firefox(executable_path=r'C:UsersCodyDownloadsgeckodriver.exe')
driver.get('http://inventwithpython.com')

This causes:

C:UsersCodyProjects>python accounting.py
Traceback (most recent call last):
  File "accounting.py", line 4, in <module>
    driver = webdriver.Firefox(executable_path=r'C:UsersCodyDownloadsgeckodriver.exe')
  File "C:UsersCodyAppDataLocalPackagesPythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0LocalCachelocal-packagesPython38site-packagesseleniumwebdriverfirefoxwebdriver.py", line 170, in __init__
    RemoteWebDriver.__init__(
  File "C:UsersCodyAppDataLocalPackagesPythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0LocalCachelocal-packagesPython38site-packagesseleniumwebdriverremotewebdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:UsersCodyAppDataLocalPackagesPythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0LocalCachelocal-packagesPython38site-packagesseleniumwebdriverremotewebdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:UsersCodyAppDataLocalPackagesPythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0LocalCachelocal-packagesPython38site-packagesseleniumwebdriverremotewebdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:UsersCodyAppDataLocalPackagesPythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0LocalCachelocal-packagesPython38site-packagesseleniumwebdriverremoteerrorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: 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

If I try:

from selenium import webdriver
driver = webdriver.Firefox(executable_path=r'C:UsersCodyDownloads')
driver.get('http://inventwithpython.com')

I get

C:UsersCodyProjects>python accounting.py
Traceback (most recent call last):
  File "C:UsersCodyAppDataLocalPackagesPythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0LocalCachelocal-packagesPython38site-packagesseleniumwebdrivercommonservice.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.8_3.8.2032.0_x64__qbz5n2kfra8p0libsubprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.8_3.8.2032.0_x64__qbz5n2kfra8p0libsubprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
PermissionError: [WinError 5] Access is denied

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "accounting.py", line 4, in <module>
    driver = webdriver.Firefox(executable_path=r'C:UsersCodyDownloads')
  File "C:UsersCodyAppDataLocalPackagesPythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0LocalCachelocal-packagesPython38site-packagesseleniumwebdriverfirefoxwebdriver.py", line 164, in __init__
    self.service.start()
  File "C:UsersCodyAppDataLocalPackagesPythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0LocalCachelocal-packagesPython38site-packagesseleniumwebdrivercommonservice.py", line 86, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'Downloads' executable may have wrong permissions.

Geckodriver.exe is sitting right there in the downloads folder.

enter image description here

Advertisement

Answer

This error message…

selenium.common.exceptions.SessionNotCreatedException: 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 locate the executable while trying to initiate/spawn a new Browsing Context i.e. Firefox Browser session.


Reason

The two primary reasons for this error are as follows:

  • Firefox isn’t installed within your system.
  • Firefox isn’t installed at the default location within your system.

Solution

The possible solutions are:

  • If Firefox isn’t installed in your system, you need to install it before executing your tests.

  • If Firefox is installed at a customized location, you need to pass the absolute path of the firefox binary as follows through an Options() instance:

    from selenium import webdriver
    
    options = webdriver.FirefoxOptions()
    options.binary_location = r"C:/location/to/Firefox/Binary/firefox.exe"
    driver = webdriver.Firefox(executable_path=r'C:UsersCodyDownloadsgeckodriver.exe', options=options)
    driver.get('http://inventwithpython.com/')
    

References

You can find a couple of relevant detailed discussion in:

Advertisement