SergeyPirogov / webdriver_manager

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ChromeDriver.install() bug

Rsalganik1123 opened this issue · comments

When trying to replicate the ChromeDriver example in the documentation, I get the following error : AttributeError: 'NoneType' object has no attribute 'split'

To reproduce:

from selenium import webdriver
from selenium.common import NoSuchElementException
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())

Used to work but suddenly doesn't -- maybe there was some update I'm not aware of?

Something similar here with a slightly different error. On my Mac M3 I get the following error.

WebDriverException: Message: Service /Users/briandekeijzer/.wdm/drivers/chromedriver/mac64/119.0.6045.105/chromedriver-mac-arm64/chromedriver unexpectedly exited. Status code was: -9

I fixed this a couple of days ago by reinstalling selenium and webdriver_manager through pip. But for some reason the error is back. My env has not changed. Running the same fix doesn't resolve the issue.

To reproduce use:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))

On Python 3.9 with selenium version 4.16.0 and webdriver-manager version 4.0.1.

Edit:

A temporary fix is to remove the .wdm folder and --upgrade the package.

rm -rf /Users/briandekeijzer/.wdm
pip install --upgrade webdriver_manager

Likely culprit:

It looks like webdriver manager can't resolve the webdriver path.

This likely means one of 3 things, it can't find chrome, it can't find chromedriver, or it can't map the correct version of chrome to the correct version of chromedriver.

Traceback

2024-01-14 18:38:15     driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
2024-01-14 18:38:15                                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-01-14 18:38:15   File "/usr/local/lib/python3.11/site-packages/webdriver_manager/chrome.py", line 40, in install
2024-01-14 18:38:15     driver_path = self._get_driver_binary_path(self.driver)
2024-01-14 18:38:15                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-01-14 18:38:15   File "/usr/local/lib/python3.11/site-packages/webdriver_manager/core/manager.py", line 40, in _get_driver_binary_path
2024-01-14 18:38:15     file = self._download_manager.download_file(driver.get_driver_download_url(os_type))
2024-01-14 18:38:15                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-01-14 18:38:15   File "/usr/local/lib/python3.11/site-packages/webdriver_manager/drivers/chrome.py", line 32, in get_driver_download_url
2024-01-14 18:38:15     driver_version_to_download = self.get_driver_version_to_download()
2024-01-14 18:38:15                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-01-14 18:38:15   File "/usr/local/lib/python3.11/site-packages/webdriver_manager/core/driver.py", line 48, in get_driver_version_to_download
2024-01-14 18:38:15     return self.get_latest_release_version()
2024-01-14 18:38:15            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-01-14 18:38:15   File "/usr/local/lib/python3.11/site-packages/webdriver_manager/drivers/chrome.py", line 64, in get_latest_release_version
2024-01-14 18:38:15     determined_browser_version = ".".join(determined_browser_version.split(".")[:3])
2024-01-14 18:38:15                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-01-14 18:38:15 AttributeError: 'NoneType' object has no attribute 'split'

I don't see how this code was ever able to work. Is it required for chrome to be installed?

in https://github.com/SergeyPirogov/webdriver_manager/blob/master/webdriver_manager/drivers/chrome.py#L54

        determined_browser_version = self.get_browser_version_from_os()
        log(f"Get LATEST {self._name} version for {self._browser_type}")
        if determined_browser_version is not None and version.parse(determined_browser_version) >= version.parse("115"):
            ...
            return determined_browser_version

        # at this point, determined_browser_version can be None if chrome is not installed, so splitting cannot work
        determined_browser_version = ".".join(determined_browser_version.split(".")[:3])
        latest_release_url = (
            self._latest_release_url
            if (determined_browser_version is None)
            else f"{self._latest_release_url}_{determined_browser_version}"
        )

I am creating a PR right away

commented

Same problem here

Temporary solution is to install the webdriver manually
for ubuntu: sudo apt install chromium-driver

Temporary solution is to install the webdriver manually for ubuntu: sudo apt install chromium-driver

This doesn't work for me. I alternatively installed a full-sized chrome with sudo apt install chromium.

Temporary solution is to install the webdriver manually for ubuntu: sudo apt install chromium-driver

This doesn't work for me. I alternatively installed a full-sized chrome with sudo apt install chromium.

Yeah that's the bug. I think when this repository was originally designed, it was designed with local instances of browsers in mind, and not remote browsers/browser-servers. So, with the original design, you had to have a local installation available.

I am having this same issue except I am attempting to run some scraping with Selenium in MWAA. Does anyone have any tips on how I could resolve it there?

I was running into this issue when using webdriver_manager in Python 3.

Solution:

  1. Get chromedriver with sudo apt install chromium-driver
  2. Skip the install and specify the Service path directly:
chromedriver_path = '/usr/bin/chromedriver' # or wherever chromedriver is installed for you
driver = webdriver.Chrome(options=options, service=Service(chromedriver_path))

For context this was the problematic code before running into the same issues others cited above:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager

options = Options()
options.headless = args.headless
driver = webdriver.Chrome(
    options=options, service=Service(ChromeDriverManager().install())
)

The simplest fix for this is just to set the driver_version, I set mine to "120" and the download worked fine. It looks like the OperationSystemManager class is unable to identify the most recent version of chrome.

def get_latest_release_version(self):
        determined_browser_version = self.get_browser_version_from_os()
        log(f"Get LATEST {self._name} version for {self._browser_type}")
        if determined_browser_version is not None and version.parse(determined_browser_version) >= version.parse("115"):
            url = "https://googlechromelabs.github.io/chrome-for-testing/latest-patch-versions-per-build.json"
            response = self._http_client.get(url)
            response_dict = json.loads(response.text)
            determined_browser_version = response_dict.get("builds").get(determined_browser_version).get("version")
            return determined_browser_version
        # Remove the build version (the last segment) from determined_browser_version for version < 113
        determined_browser_version = ".".join(determined_browser_version.split(".")[:3])
        latest_release_url = (
            self._latest_release_url
            if (determined_browser_version is None)
            else f"{self._latest_release_url}_{determined_browser_version}"
        )
        resp = self._http_client.get(url=latest_release_url)
        return resp.text.rstrip()

I think it would be a good idea to check that determined_browser_version isn't None before being split, and just set it to a hard coded default value if it is. Or it might even better better to fix upstream in get_browser_version_from_os, and make that return a hard coded default value.

Solution:

    from webdriver_manager.chrome import ChromeDriverManager
    print(ChromeDriverManager(driver_version='120').install())
commented

Same issue here.
Environment:
Windows 11
Python 3.9.17
Webdriver_manager 4.0.1

error msgs:

'powershell' is not recognized as an internal or external command,
operable program or batch file.
'powershell' is not recognized as an internal or external command,
operable program or batch file.
'powershell' is not recognized as an internal or external command,
operable program or batch file.
...
  File "c:\Users\username\AppData\Local\miniconda3\envs\env\lib\site-packages\webdriver_manager\drivers\chrome.py", line 64, in get_latest_release_version
    determined_browser_version = ".".join(determined_browser_version.split(".")[:3])
AttributeError: 'NoneType' object has no attribute 'split'

solution:
I changed shell=True to shell=False in webdriver_manager\core\utils.py, L43.
image

I recommend checking the system type to determine the value of this Boolean.

commented

Yeah, ive been having issues as well. Just confused, first time wanting to use google chrome through my bot. Just getting errors where its not finding google chrome. Am I supposed to install google chrome in my bots file? As this is in a server, not my own os.

I think that is currently the expectation. Webdriver itself doesn't require a local installation of Chrome, but running Chrome remotely used to be a niche use case. This library was written when running remote instances wasn't very common. At least not as common as running it locally.

Technically, you only need chrome installed. I don't believe that this library actually launches Chrome.

I'm also getting this error and I don't know why, because I have Chrome installed.

Hello guys!
Worked for me to download the chromedriver with the same version as my browser, using the link from this website: https://googlechromelabs.github.io/chrome-for-testing/#stable

And then I just provided the path like this:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

service = Service(executable_path='CHROME_DRIVER_PATH')
browser = webdriver.Chrome(service=service)

Hello guys! Worked for me to download the chromedriver with the same version as my browser, using the link from this website: https://googlechromelabs.github.io/chrome-for-testing/#stable

And then I just provided the path like this:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

service = Service(executable_path='CHROME_DRIVER_PATH')
browser = webdriver.Chrome(service=service)

This link yesterday was able to get me version 125, but today it can't, I guess good thing I downloaded it when I did.. but now my program throws this error:
from session not created: This version of ChromeDriver only supports Chrome version 126 Current browser version is 125.0.6422.141
and I need to get 126 instead, even though just an hour ago it was fine with 125. Extremely strange