3

I am running the following Python code with Selenium:

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()))

and I have ensured that Firefox is installed on my machine and that the executable is in my PATH.

However, I keep getting the following error:

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

3

4 Answers 4

2

The error you're encountering is because the options object is not being passed to the webdriver.Firefox constructor.

You need to replace this part of your code:

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

with this:

driver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install()), options=options)
Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

I tried this but it had no effect. I still get the same error.
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)

Comments

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()

1 Comment

Replace path with your torr browser path

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.