SeleniumHQ / selenium

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

[🐛 Bug]: Selenium Manager 4.11.2 not finding or auto-downloading the Web Driver #12627

Closed altoorodevelead closed 1 year ago

altoorodevelead commented 1 year ago

What happened?

Hello, I'm trying to run Selenium 4.11 and to use the Selenium Manager to auto download the browser/driver. This is the code:

from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.google.com")

But i'm getting the usual:

Unable to obtain driver for chrome using Selenium Manager...

How can we reproduce the issue?

Not 100% sure if it is reproducible or an isolated issue, because I tried the suggested solution found on GitHub, but it did not work.

- Python version 3.11.2
- PyCharm on Mac
- macOS Monterey 12.6.3

Relevant log output

service = <selenium.webdriver.chrome.service.Service object at 0x105e33590>
options = <selenium.webdriver.chrome.options.Options object at 0x105e33550>

    @staticmethod
    def get_path(service: Service, options: BaseOptions) -> str:
        path = service.path
        try:
            path = SeleniumManager().driver_location(options) if path is None else path
        except Exception as err:
            msg = f"Unable to obtain driver for {options.capabilities['browserName']} using Selenium Manager."
>           raise NoSuchDriverException(msg) from err
E           selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain driver for chrome using Selenium Manager.; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location

/Users/julian/Desktop/Altooro/automation_tests/env/lib/python3.11/site-packages/selenium/webdriver/common/driver_finder.py:41: NoSuchDriverException

Operating System

macOS Monterey

Selenium version

Python 4.11.2

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

Chrome 116

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

Chrome 116

Are you using Selenium Grid?

No

github-actions[bot] commented 1 year ago

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

titusfortner commented 1 year ago

Can you turn on logging and post results — https://www.selenium.dev/documentation/webdriver/troubleshooting/logging/

altoorodevelead commented 1 year ago

Can you turn on logging and post results — https://www.selenium.dev/documentation/webdriver/troubleshooting/logging/

Thank you for the reply. I will make sure to do so and update you.

matt-riemer commented 1 year ago

Hello my friends :)

My ruby on rails CircleCI builds have begun to fail today, Aug 29th 2023

CleanShot 2023-08-29 at 16 48 57

Maybe related?

Thanks

diemol commented 1 year ago

Your issue looks different. Starting from ChromeDriver 115 the download url has changed.

https://googlechromelabs.github.io/chrome-for-testing/

altoorodevelead commented 1 year ago

We turned on the logging, but not much extra was logged, an output was put in a file:

Selenium Manager binary found at: /Users/julian/Desktop/Altooro/automation_tests/env/lib/python3.11/site-packages/selenium/webdriver/common/macos/selenium-manager
Executing process: /Users/julian/Desktop/Altooro/automation_tests/env/lib/python3.11/site-packages/selenium/webdriver/common/macos/selenium-manager --browser chrome --debug --output json
titusfortner commented 1 year ago

Pytest makes it incredibly difficult to actually see the logs.

Can you execute that last line manually in Terminal?

altoorodevelead commented 1 year ago

Here you go:

Traceback (most recent call last):
  File "/Users/julian/Desktop/Altooro/automation_tests/env/lib/python3.11/site-packages/selenium/webdriver/common/selenium_manager.py", line 126, in run
    output = json.loads(stdout)
             ^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

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

Traceback (most recent call last):
  File "/Users/julian/Desktop/Altooro/automation_tests/env/lib/python3.11/site-packages/selenium/webdriver/common/driver_finder.py", line 38, in get_path
    path = SeleniumManager().driver_location(options) if path is None else path
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/julian/Desktop/Altooro/automation_tests/env/lib/python3.11/site-packages/selenium/webdriver/common/selenium_manager.py", line 90, in driver_location
    output = self.run(args)
             ^^^^^^^^^^^^^^
  File "/Users/julian/Desktop/Altooro/automation_tests/env/lib/python3.11/site-packages/selenium/webdriver/common/selenium_manager.py", line 129, in run
    raise WebDriverException(f"Unsuccessful command executed: {command}") from err
selenium.common.exceptions.WebDriverException: Message: Unsuccessful command executed: /Users/julian/Desktop/Altooro/automation_tests/env/lib/python3.11/site-packages/selenium/webdriver/common/macos/selenium-manager --browser chrome --output json

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

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/julian/Desktop/Altooro/automation_tests/env/lib/python3.11/site-packages/selenium/webdriver/chrome/webdriver.py", line 45, in __init__
    super().__init__(
  File "/Users/julian/Desktop/Altooro/automation_tests/env/lib/python3.11/site-packages/selenium/webdriver/chromium/webdriver.py", line 51, in __init__
    self.service.path = DriverFinder.get_path(self.service, options)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/julian/Desktop/Altooro/automation_tests/env/lib/python3.11/site-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 chrome using Selenium Manager.; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location
titusfortner commented 1 year ago

Execute this in the command line so we don't have to deal with PyTest getting in the way of the info:

/Users/julian/Desktop/Altooro/automation_tests/env/lib/python3.11/site-packages/selenium/webdriver/common/macos/selenium-manager --browser chrome --debug --output json
altoorodevelead commented 1 year ago

So super weird thing just happened, I opened a new terminal window, ran the command and got a "Permission denied" sort of message.

Then, ran the same command with sudo prefixed, a JSON was outputted with a list of drivers:

{
  "logs": [
    {
      "level": "DEBUG",
      "timestamp": 1693403830,
      "message": "Checking chromedriver in PATH"
    },
    {
      "level": "DEBUG",
      "timestamp": 1693403830,
      "message": "Running command: chromedriver --version"
    },
    {
      "level": "DEBUG",
      "timestamp": 1693403830,
      "message": "Output: \"ChromeDriver 116.0.5845.96 (1a391816688002153ef791ffe60d9e899a71a037-refs/branch-heads/5845@{#1382})\""
    },
    {
      "level": "DEBUG",
      "timestamp": 1693403830,
      "message": "Running command: which chromedriver"
    },
    {
      "level": "DEBUG",
      "timestamp": 1693403830,
      "message": "Output: \"/usr/local/bin/chromedriver\""
    },
    {
      "level": "DEBUG",
      "timestamp": 1693403830,
      "message": "Found chromedriver 116.0.5845.96 in PATH: /usr/local/bin/chromedriver"
    },
    {
      "level": "DEBUG",
      "timestamp": 1693403830,
      "message": "chrome detected at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
    },
    {
      "level": "DEBUG",
      "timestamp": 1693403830,
      "message": "Using shell command to find out chrome version"
    },
    {
      "level": "DEBUG",
      "timestamp": 1693403830,
      "message": "Running command: /Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --version"
    },
    {
      "level": "DEBUG",
      "timestamp": 1693403830,
      "message": "Output: \"Google Chrome 116.0.5845.110 \""
    },
    {
      "level": "DEBUG",
      "timestamp": 1693403830,
      "message": "Detected browser: chrome 116.0.5845.110"
    },
    {
      "level": "DEBUG",
      "timestamp": 1693403830,
      "message": "Required driver: chromedriver 116.0.5845.96"
    },
    {
      "level": "INFO",
      "timestamp": 1693403830,
      "message": "Driver path: /usr/local/bin/chromedriver"
    },
    {
      "level": "INFO",
      "timestamp": 1693403830,
      "message": "Browser path: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
    }
  ],
  "result": {
    "code": 0,
    "message": "/usr/local/bin/chromedriver",
    "driver_path": "/usr/local/bin/chromedriver",
    "browser_path": "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
  }
}

I assumed that this meant that the SeleniumManager should work, so I executed this code once more:

from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.google.com")

And it worked flawlessly, the browser opened and everything!

Thinking that the permission might reset if I restart the laptop, I did so, but no, running the same command without sudo this time it kept working, and the Python code now runs normally.

altoorodevelead commented 1 year ago

Update, the "permission issue" is back when calling:

/Users/julian/Desktop/Altooro/automation_tests/env/lib/python3.11/site-packages/selenium/webdriver/common/macos/selenium-manager --browser chrome --debug --output json

Here is the output:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }', src/metadata.rs:164:6
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[1]    5581 abort       --browser chrome --debug --output json

If we run with sudo it works, but only for a few hours.

titusfortner commented 1 year ago

Selenium can't fix permission issues on your computer. Elevate privileges of user or allow executing files in that directory to all users

We are going to put the driver in a specific location in 4.13 that might make it easier.

chamodi179 commented 1 year ago

i am using the firefox 113 and i want to know weather the following code is correct or not.

self.options = Options()self.options.add_argument('--ignore-certificate-errors') self.options.add_argument('--ignore-ssl-errors') self.profile = webdriver.FirefoxProfile() if os.environ.get('IS_SERVER') == "1": self.profile.set_preference("browser.cache.disk.enable", False) self.profile.set_preference("browser.cache.memory.enable", False) self.profile.set_preference("browser.cache.offline.enable", False) self.profile.set_preference("network.http.use-cache", False)

self.options.add_argument('--headless')

        self.options.headless = True

def my_driver(self): try: self.helper.check_connection()

self.tor_handler.renew_connection()

            options = FirefoxOptions()
            self.profile.update_preferences()
            firefox_driver = webdriver.Firefox(options=options)
            webdriver_wait = WebDriverWait(firefox_driver, 25, poll_frequency=1)
            firefox_driver.set_page_load_timeout(200)
            return True, firefox_driver, webdriver_wait
       except:
            traceback.print_exc()
            return False
github-actions[bot] commented 11 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.