Selenium "no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line"

Viewed 55

I have been attempting to port a python script into my wsl/bash hub of coding.

I continue to get this error:

Traceback (most recent call last):
  File "/path/to/my/file.py", line 20, in <module>
    driver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install()))
  File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/firefox/webdriver.py", line 177, in __init__
    super().__init__(
  File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 270, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 363, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 428, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/errorhandler.py", line 243, 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

I have searched here on StackOverflow as well as other places and found answers that have not helped my issue. I have ensured that firefox is installed on my machine, and the executable is in my PATH but it still shoots out this error.

Here is my code that I believe is causing the issue.

options = Options()
options.binary_location = r'C:\Program Files\Mozilla Firefox\firefox.exe'
options.set_preference('dom.webnotifications.enabled', False)
options.headless = True

driver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install()))

Any help would be greatly appreciated.

1 Answers

I had the same problem.

For me,

  1. I reinstalled Firefox using an offline Installer. ( Apparently, it sets a different path in registry when you install online-install version)

  2. then I set geckodriver.exe as PATH and that fixed the issue.

Hope this helps. cheers

Related