SeleniumHQ / selenium

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

[🐛 Bug]: Unable to obtain driver for firefox using Selenium Manager #14130

Closed CTCompSec closed 1 week ago

CTCompSec commented 2 weeks ago

What happened?

Update: I fixed this problem by uninstalling the old version with my package manager and then installing the newest version of Selenium using pip. Going to keep this here even though it is fixed for others to see.

I'm working in python3 trying to use Selenium. It seems that Selenium is unable to locate the driver.

Here is the code that I am running:

from selenium import webdriver

driver = webdriver.Firefox()
driver.quit()

And here's my output:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/selenium/webdriver/common/driver_finder.py", line 38, in get_path
    path = SeleniumManager().driver_location(options) if path is None else path
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/selenium/webdriver/common/selenium_manager.py", line 73, in driver_location
    args = [str(self.get_binary()), "--browser", browser]
                ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/selenium/webdriver/common/selenium_manager.py", line 57, in get_binary
    raise WebDriverException(f"Unable to obtain working Selenium Manager binary; {path}")
selenium.common.exceptions.WebDriverException: Message: Unable to obtain working Selenium Manager binary; /usr/lib/python3/dist-packages/selenium/webdriver/common/linux/selenium-manager

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/carlos/InformationSecurityMedia/temp.py", line 4, in <module>
    driver = webdriver.Firefox()
             ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
    self.service.path = DriverFinder.get_path(self.service, options)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/selenium/webdriver/common/driver_finder.py", line 41, in get_path
    raise NoSuchDriverException(msg) from err
selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain driver for firefox using Selenium Manager.; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location

I'm using zsh on Ubuntu, and I know that geckodriver is on the path because I can run this command:

geckodriver --version
geckodriver 0.34.0 (c44f0d09630a 2024-01-02 15:36 +0000)

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/.

How can we reproduce the issue?

from selenium import webdriver

driver = webdriver.Firefox()
driver.quit()

Relevant log output

Traceback (most recent call last):
  File "/home/carlos/InformationSecurityMedia/temp.py", line 4, in <module>
    driver = webdriver.Firefox()
             ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
    self.service.path = DriverFinder.get_path(self.service, options)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/selenium/webdriver/common/driver_finder.py", line 41, in get_path
    raise NoSuchDriverException(msg) from err
selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain driver for firefox using Selenium Manager.; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location

Operating System

Ubuntu 23.10

Selenium version

4.11.2

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

125.0.2

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

Geckodriver

Are you using Selenium Grid?

No response

github-actions[bot] commented 2 weeks ago

@CTCompSec, 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!

pujagani commented 2 weeks ago

Can you to upgrade to the latest Selenium version and try?

jintanzhen commented 2 weeks ago

I got a same question! And my selenium version is 4.21.0 ! This is a latest! Maybe we should use browser driver,like chromedriver,but why? Selenium said "As of Selenium 4.6, Selenium downloads the correct driver for you. ", so....

github-actions[bot] commented 2 weeks ago

We need more information about this issue in order to troubleshoot.

Please turn on logging and re-run your code. Information on how to adjust logs for your language can be found in our Troubleshooting documentation.

CTCompSec commented 1 week ago

Can you to upgrade to the latest Selenium version and try?

It is already the latest version

titusfortner commented 1 week ago

Your report says 4.11.2 which is not the latest version. Please update to the latest version, turn on logging and provide the results.

CTCompSec commented 1 week ago

Your report says 4.11.2 which is not the latest version. Please update to the latest version, turn on logging and provide the results.

Thank you guys for your prompt responses I really appreciate the work that you are doing

I typically use apt as my package manager for Ubuntu. When I run apt, this is my output:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
python3-selenium is already the newest version (4.11.2+dfsg-1).
0 upgraded, 0 newly installed, 0 to remove and 28 not upgraded.

It would be ideal if I could get the new version on apt since I don't really like switching out my package manager.

If that's not possible I can absolutely use a different package manager. Just let me know.

I've implemented logging with this script:

import logging
from selenium import webdriver

def test_logging(log_path):
    logger = logging.getLogger('selenium')

    logger.setLevel(logging.DEBUG)

    handler = logging.FileHandler(log_path)
    logger.addHandler(handler)

    logging.getLogger('selenium.webdriver.remote').setLevel(logging.WARN)
    logging.getLogger('selenium.webdriver.common').setLevel(logging.DEBUG)

    logger.info("this is useful information")
    logger.warning("this is a warning")
    logger.debug("this is detailed debug information")

 with open(log_path, 'r') as fp:
        assert len(fp.readlines()) == 3

driver = webdriver.Firefox()
driver.quit()

And this is my output:

1 carlos@carlosComputer ~/InformationSecurityMedia % python3 temp.py
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/selenium/webdriver/common/driver_finder.py", line 38, in get_path
    path = SeleniumManager().driver_location(options) if path is None else path
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/selenium/webdriver/common/selenium_manager.py", line 73, in driver_location
    args = [str(self.get_binary()), "--browser", browser]
                ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/selenium/webdriver/common/selenium_manager.py", line 57, in get_binary
    raise WebDriverException(f"Unable to obtain working Selenium Manager binary; {path}")
selenium.common.exceptions.WebDriverException: Message: Unable to obtain working Selenium Manager binary; /usr/lib/python3/dist-packages/selenium/webdriver/common/linux/selenium-manager

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/carlos/InformationSecurityMedia/temp.py", line 23, in <module>
    driver = webdriver.Firefox()
             ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
    self.service.path = DriverFinder.get_path(self.service, options)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/selenium/webdriver/common/driver_finder.py", line 41, in get_path
    raise NoSuchDriverException(msg) from err
selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain driver for firefox using Selenium Manager.; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location

Thank you for your time

titusfortner commented 1 week ago

We've seen a number of bug fixes in Selenium Manager this year, and we can't fix problems in old versions, only the current version.

Package managers make sense for managing applications like browsers and Python itself. For coding projects, though, Python devs typically use requirements.txt and pip to manage specific versions of dependencies without having to rely on what is pre-installed on the system. Then again, none of this is as easy as it could be in Python... https://xkcd.com/1987/

CTCompSec commented 1 week ago

We've seen a number of bug fixes in Selenium Manager this year, and we can't fix problems in old versions, only the current version.

Package managers make sense for managing applications like browsers and Python itself. For coding projects, though, Python devs typically use requirements.txt and pip to manage specific versions of dependencies without having to rely on what is pre-installed on the system. Then again, none of this is as easy as it could be in Python... https://xkcd.com/1987/

Ah yes the infinite wisdom of xkcd.

I did go ahead and remove everything with apt then start pip install and it seems to have solved that problem.

So thank you.

I'm still getting

*** You are running in headless mode.
[GFX1-]: RenderCompositorSWGL failed mapping default framebuffer, no dt
carlos@carlosComputer ~/InformationSecurityMedia/venv % 
titusfortner commented 1 week ago

Create an options class and pass in an argument for --headless=new https://www.selenium.dev/documentation/webdriver/browsers/chrome/?tab=python#arguments

I'll throw some links below for where you can get more questions answered.

github-actions[bot] commented 1 week ago

💬 Please ask questions at: