webdriver_manager icon indicating copy to clipboard operation
webdriver_manager copied to clipboard

ChromeDriver.install() bug

Open Rsalganik1123 opened this issue 1 year ago • 18 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?

Rsalganik1123 avatar Dec 19 '23 05:12 Rsalganik1123

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

deKeijzer avatar Dec 28 '23 19:12 deKeijzer

Likely culprit:

  • https://github.com/SergeyPirogov/webdriver_manager/blob/master/webdriver_manager/chrome.py#L40C28-L40C51

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.

anonhostpi avatar Jan 09 '24 06:01 anonhostpi

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'

vorenhoutgithub avatar Jan 14 '24 17:01 vorenhoutgithub

image

Lyapsus avatar Jan 15 '24 01:01 Lyapsus

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

MarcBresson avatar Jan 16 '24 09:01 MarcBresson

Same problem here

oezeb avatar Jan 31 '24 21:01 oezeb

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

wilsonsdev avatar Apr 01 '24 21:04 wilsonsdev

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.

junekhan avatar Apr 03 '24 11:04 junekhan

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.

anonhostpi avatar Apr 04 '24 16:04 anonhostpi

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?

nrmiller5 avatar Apr 05 '24 00:04 nrmiller5

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())
)

kmahorker avatar Apr 10 '24 07:04 kmahorker

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())

LagSlug avatar Apr 10 '24 12:04 LagSlug

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.

joon612 avatar May 27 '24 05:05 joon612

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.

zerxdapro avatar May 29 '24 05:05 zerxdapro

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.

anonhostpi avatar May 29 '24 06:05 anonhostpi

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

debthomaz avatar Jun 07 '24 18:06 debthomaz

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)

debthomaz avatar Jun 10 '24 21:06 debthomaz

This Solution written above works great for me running python under cygwin/Mobaterm. I think maybe the library is getting mixed up about whether I'm using Windows or Linux.

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

KuleRucket avatar Jul 02 '24 15:07 KuleRucket