SessionNotCreatedException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary'
Asked Answered
R

2

14

When I try to create a Firefox instance in Selenium, I get the following 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

I'm running on Ubuntu 20.04 (Focal Fossa).

How can I fix it?

browser = webdriver.Firefox()

Traceback (most recent call last):
  File "key.py", line 10, in <module>
    browser = webdriver.Firefox()
  File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/firefox/webdriver.py", line 170, in __init__
    RemoteWebDriver.__init__(
  File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/errorhandler.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
Reprobative answered 19/11, 2020 at 8:44 Comment(2)
run ">whereis firefox" command and set that path in FirefoxOptionsMisplace
You need firefox binary and geckodriver installed. Put them in your $PATHCurler
V
19

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 firefox binary while trying to initiate/spawn a new Browsing Context i.e. Firefox Browser session.


Reason

The probable reason for this error can be either of the following:

  • Firefox isn't installed in your system.
  • Firefox isn't installed in 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
    from selenium.webdriver.firefox.options import Options
    
    options = Options()
    options.binary_location = r"C:/location/to/Firefox/Binary/firefox.exe"
    driver = webdriver.Firefox(options=options, executable_path="C:/location/to/geckodriver.exe")
    driver.get('http://google.com/')
    

References

You can find a couple of relevant detailed discussion in:

Vassalize answered 19/11, 2020 at 9:33 Comment(0)
S
6

It worked for me by passing FirefoxBinary() options.

Code below worked for me.

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium import webdriver
firefox_binary = FirefoxBinary()
driver = webdriver.Firefox(firefox_binary=firefox_binary)

The above code will surely work for everyone.

Supersaturated answered 28/12, 2022 at 6:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.