SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.56k stars 8.17k forks source link

[🐛 Bug]: Message: binary is not a Firefox executable #14602

Open Davide-Leo opened 1 week ago

Davide-Leo commented 1 week ago

What happened?

Even by specifying driver path and browser path (as said here: https://github.com/SeleniumHQ/selenium/issues/13169 and here: https://www.selenium.dev/documentation/selenium_manager/#custom-package-managers ) I still get the "binary is not a Firefox executable" message.

from selenium.webdriver import FirefoxOptions
from selenium import webdriver
import selenium.webdriver.firefox.service as FirefoxService

options = FirefoxOptions()

# which firefox
# /usr/bin/firefox
options.binary_location = "/usr/bin/firefox"

# which geckodriver
# /snap/bin/geckodriver
firefoxdriver_bin = "/snap/bin/geckodriver" 
service = FirefoxService.Service(executable_path=firefoxdriver_bin)

driver = webdriver.Firefox(service=service, options=options)
driver.get("https://pythonbasics.org")

By running

/usr/bin/firefox

The browser is properly launched.

How can we reproduce the issue?

python version: Python 3.12.3

apt install firefox
pip install selenium
python provided_script.py

Relevant log output

Traceback (most recent call last):
  File ".../prova.py", line 16, in <module>
    driver = webdriver.Firefox(service=service, options=options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/.../anaconda3/envs/aiweb/lib/python3.12/site-packages/selenium/webdriver/firefox/webdriver.py", line 71, in __init__
    super().__init__(command_executor=executor, options=options)
  File "/home/.../anaconda3/envs/aiweb/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 212, in __init__
    self.start_session(capabilities)
  File "/home/.../anaconda3/envs/aiweb/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 299, in start_session
    response = self.execute(Command.NEW_SESSION, caps)["value"]
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/.../anaconda3/envs/aiweb/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 354, in execute
    self.error_handler.check_response(response)
  File "/home/.../anaconda3/envs/aiweb/lib/python3.12/site-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: binary is not a Firefox executable

Operating System

Ubuntu 22.04.4 LTS

Selenium version

Version: 4.25.0

What are the browser(s) and version(s) where you see this issue?

/usr/bin/firefox --version

-->

Mozilla Firefox 131.0.2

What are the browser driver(s) and version(s) where you see this issue?

/snap/bin/geckodriver --version

-->

geckodriver 0.35.0 ( 2024-10-08)

The source code of this program is available from testing/geckodriver in https://hg.mozilla.org/mozilla-central.

This program is subject to the terms of the Mozilla Public License 2.0. You can obtain a copy of the license at https://mozilla.org/MPL/2.0/.

Are you using Selenium Grid?

No response

github-actions[bot] commented 1 week ago

@Davide-Leo, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

Delta456 commented 1 week ago

I can't reproduce this on my Mac machine with my binary location. The scripts works correctly for me.

from selenium.webdriver import FirefoxOptions
from selenium import webdriver
import selenium.webdriver.firefox.service as FirefoxService

options = FirefoxOptions()

# which firefox
# /usr/bin/firefox
options.binary_location = "/Applications/Firefox.app/Contents/MacOS/firefox"

# which geckodriver
# /snap/bin/geckodriver
firefoxdriver_bin = "/Users/user/Downloads/geckodriver" 
service = FirefoxService.Service(executable_path=firefoxdriver_bin)

driver = webdriver.Firefox(service=service, options=options)
driver.get("https://pythonbasics.org")
VietND96 commented 1 week ago

Execute those path of firefox and geckodriver with --version. Can it return version info properly?

Davide-Leo commented 6 days ago

The version I have is the one I provided under the section