Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided using GeckoDriver
This 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.
...implies that the GeckoDriver was unable to find the Firefox binary at the default location. Additionally you haven't passed the moz:firefoxOptions.binary
capability.Solution
Possibly within your system firefox is installed in a custom location and these cases you need to pass the absolute path of the Firefox binary through the moz:firefoxOptions.binary
capability as follows:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.binary_location = r'C:\Program Files\Mozilla Firefox\firefox.exe'
driver = webdriver.Firefox(executable_path=r'C:\WebDrivers\geckodriver.exe', options=options)
driver.get('http://google.com/')
References
You can find a couple of relevant detailed discussion in:
- SessionNotCreatedException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary'
- InvalidArgumentException: Message: binary is not a Firefox executable error using GeckoDriver Firefox Selenium and Python
- Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided
Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided
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 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:\Users\Cody\Downloads\geckodriver.exe', options=options)
driver.get('http://inventwithpython.com/')
References
You can find a couple of relevant detailed discussion in:
- SessionNotCreatedException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary'
- InvalidArgumentException: Message: binary is not a Firefox executable error using GeckoDriver Firefox Selenium and Python
- Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided using GeckoDriver
Related Topics
How to Set Selenium Python Webdriver Default Timeout
Python & Selenium: Difference Between Driver.Implicitly_Wait() and Time.Sleep()
Getting Gradient of Model Output W.R.T Weights Using Keras
How to Customize Title Bar and Window of Desktop Application
Typeerror: Only Length-1 Arrays Can Be Converted to Python Scalars While Plot Showing
Find All Upper, Lower and Mixed Case Combinations of a String
Suppressing Scientific Notation in Pandas
How May I Override the Compiler (Gcc) Flags That Setup.Py Uses by Default
_Getattr_ for Static/Class Variables
Python MySQL Connector - Unread Result Found When Using Fetchone
Cheap Way to Search a Large Text File for a String
How to Specify Python Version Used to Create Virtual Environment
Slicing of a Numpy 2D Array, or How to Extract an Mxm Submatrix from an Nxn Array (N>M)
How to Restrict Foreign Keys Choices to Related Objects Only in Django