InvalidArgumentException: Message: binary is not a Firefox executable error using GeckoDriver Firefox Selenium and Python InvalidArgumentException: Message: binary is not a Firefox executable error using GeckoDriver Firefox Selenium and Python selenium selenium

InvalidArgumentException: Message: binary is not a Firefox executable error using GeckoDriver Firefox Selenium and Python


This error message...

selenium.common.exceptions.InvalidArgumentException: Message: binary is not a Firefox executable

...implies that the binary file which you have passed as an argument to FirefoxBinary() isn't a valid executable.

You seem to have passed the absolute path of the geckodriver.exe as an argument to FirefoxBinary() which is causing the error.


Solution

Instead of the geckodriver.exe you need to pass the absolute path of the firefox.exe. Moreover, firefox_options is deprecated now and you have to use options and you can use the following solution:

from selenium import webdriverfrom selenium.webdriver.firefox.options import Optionsfrom selenium.webdriver.firefox.firefox_binary import FirefoxBinaryoptions = Options()options.binary = FirefoxBinary(r'C:\Program Files\Mozilla Firefox\firefox.exe')options.set_preference("browser.download.folderList",2)options.set_preference("browser.download.manager.showWhenStarting", False)options.set_preference("browser.download.dir","/Data")options.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream,application/vnd.ms-excel")driver = webdriver.Firefox(executable_path=r'C:/Users/Mack/AppData/Local/Programs/Python/Python38-32/geckodriver-v0.27.0-win64/geckodriver.exe', options=options)

References

You can find a couple of relevant detailed discussion in:


Change the binary to whatever firefox.exe you get and your executable path to your geckodriver.

options = Options()binary = r'C:\Program Files\Mozilla Firefox\firefox.exe'options.set_preference("browser.download.folderList",2)options.set_preference("browser.download.manager.showWhenStarting", False)options.set_preference("browser.download.dir","/Data")options.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream,application/vnd.ms-excel")options.binary = binarydriver = webdriver.Firefox(r'C:/Users/Mack/AppData/Local/Programs/Python/Python38-32/geckodriver-v0.27.0-win64/geckodriver.exe',options=options)


It seems that when using Firefox Portable, the FirefoxPortable.exe file is not recognized, instead, when creating binary path, point to firefox.exe file found under "FirefoxPortable\App\firefox64" (in my case). The above is valid if your Gecko driver works - so the first few lines of output (before the exception) look something like this:

[RemoteTestNG] detected TestNG version 7.3.01611580278948   geckodriver INFO    Listening on 127.0.0.1:18391

This issue appeared for me after the problem described here:Cannot find firefox binary in PATH. Make sure firefox is installedthus, they are not the same issue - as presented in some stack comments.

good luck!