selenium: [🐛 Bug]: Message: binary is not a Firefox executable
Description
I have a python script I have working on one computer, but when I try to run it on my server I get the following error:
self.driver = webdriver.Firefox(service=service, options=options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.12/site-packages/selenium/webdriver/firefox/webdriver.py", line 71, in __init__
super().__init__(command_executor=executor, options=options)
File ".venv/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 241, in __init__
self.start_session(capabilities)
File ".venv/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 329, in start_session
response = self.execute(Command.NEW_SESSION, caps)["value"]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 384, in execute
self.error_handler.check_response(response)
File ".venv/lib/python3.12/site-packages/selenium/webdriver/remote/errorhandler.py", line 232, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: binary is not a Firefox executable
Here is the code I’m running:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
import selenium.webdriver.firefox.service as FirefoxService
options = Options()
service = FirefoxService.Service(executable_path='/snap/bin/geckodriver')
options.binary_location = "/usr/bin/firefox"
webdriver.Firefox(service=service, options=options)
On my computer where this worked, I didn’t need to specify locations for geckodriver or firefox. If I get rid of the arguments to webdriver.Firefox, I get the same result, by the way, so I’m not sure they’re doing anything…
Here is some relevant version info for the original computer where this worked:
- OS: Linux Mint 22.1
- Python v3.12.3
- Selenium v4.27.1
- Firefox v135.0.1
- Gecko - interestingly
which geckodriverreturns nothing
Here is some version information for the server where I am encountering this issue:
- OS: Ubuntu 22.04.5 LTS
- Python v3.12.10
- Selenium v4.31.0
- Firefox v138.0
- Gecko v0.36.0
Reproducible Code
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
import selenium.webdriver.firefox.service as FirefoxService
options = Options()
service = FirefoxService.Service(executable_path='/snap/bin/geckodriver')
options.binary_location = "/usr/bin/firefox"
webdriver.Firefox(service=service, options=options)
Debugging Logs
self.driver = webdriver.Firefox(service=service, options=options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.12/site-packages/selenium/webdriver/firefox/webdriver.py", line 71, in __init__
super().__init__(command_executor=executor, options=options)
File ".venv/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 241, in __init__
self.start_session(capabilities)
File ".venv/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 329, in start_session
response = self.execute(Command.NEW_SESSION, caps)["value"]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 384, in execute
self.error_handler.check_response(response)
File ".venv/lib/python3.12/site-packages/selenium/webdriver/remote/errorhandler.py", line 232, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: binary is not a Firefox executable
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 18 (11 by maintainers)
Sorry for the confusion, but if you read the end of my post carefully, you’ll see that that log file you are quoting is from the run where I reinstalled Firefox (
sudo apt install firefox) and where my geckodriver was from snap but my Firefox was not.Because my post was getting long, I did not post the log file for the final run I tried after running
sudo apt remove firefox. Instead, I just posted the paths of geckodriver / firefox as they appeared in the log file.Just wanted to make sure that it was clear that I didn’t need to abandon snap entirely to get my problems to go away. Rather, I just had to ensure I wasn’t mismatching snap and non-snap…
Of course, I do take your point that it still might be best to just forgo snap altogether.