0

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.

Ian Hunt
  • 1
  • 1
  • 2
  • Please provide enough code so others can better understand or reproduce the problem. – Community Sep 14 '22 at 08:44
  • Please refer to the solution here, https://stackoverflow.com/questions/65318382/expected-browser-binary-location-but-unable-to-find-binary-in-default-location . – Mark K Oct 16 '22 at 02:51
  • Please find the below link to get the answer. https://stackoverflow.com/a/75257015/14526303 – Prashant Rajput Jan 27 '23 at 11:06

3 Answers3

0

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

0

Add below line before running driver

from selenium.webdriver.firefox.options import Options

options = Options()

options.binary_location = r'C:\Program Files\Mozilla Firefox\firefox.exe'

executable_path='C:\geckodriver'

selenium = WebDriver(executable_path=executable_path, options=options)
Pikamander2
  • 7,332
  • 3
  • 48
  • 69
vaishali KUNJIR
  • 997
  • 11
  • 9
0

This code will run without any error

from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options

# provide a full path of the driver (replace this with your filepath)
path = r"E:\toor\Tor Browser1\Browser\firefox.exe"

# pass the driver path as a service
service = Service(path)
driver = webdriver.Firefox(service=service)

driver.set_page_load_timeout(30)
driver.get("https://www.google.com/")
driver.quit()
Pikamander2
  • 7,332
  • 3
  • 48
  • 69