webdriver_manager icon indicating copy to clipboard operation
webdriver_manager copied to clipboard

ChromerDriverManager not returning correct path for the chrome driver

Open Hasnain-20 opened this issue 1 year ago • 23 comments

Description The chrome got updated on 23-07-2024 to the version 127.0.6533.72 and so does the chrome_driver. I prepared the new script and downloaded the Chrome Driver via service ChromeDriverManger from webdriver_manager .chrome. and it isn't returning the correct path of the binary. The path returned is mentioned in Error Log section.

The following files were found the downloaded chrome driver binary folder. image

Browser and version: Chrome, version 127.0.6533.72

Operating system and architecture: Linux x64

Selenium version: 4.22.0

WebDriverManager version: 4.0.1

WebDriverManager call:

driver_path = ChromeDriverManager().install()
driver = webdriver.Chrome(service=Service(driver_path))

Error log: image

Solution: I solved the issue by using following piece of code

driver_path = ChromeDriverManager().install()
if driver_path:
    driver_name = driver_path.split('/')[-1]
    if driver_name!="chromedriver":
        driver_path = "/".join(driver_path.split('/')[:-1]+["chromedriver"])
        os.chmod(driver_path, 0o755)
driver = webdriver.Chrome(service=Service(driver_path))

Hasnain-20 avatar Jul 24 '24 08:07 Hasnain-20

+1

mhdzumair avatar Jul 24 '24 10:07 mhdzumair

Seems like new distribution of chromedriver includes THIRD_PARTY_NOTICES.chromedriver next to chromedriver binary.

webdriver_manager.core.driver_cache.DriverCacheManager.__get_binary is failing to resolve the binary correctly

def __get_binary(self, files, driver_name):
        if not files:
            raise Exception(f"Can't find binary for {driver_name} among {files}")

        if len(files) == 1:
            return files[0]

        for f in files:
            if 'LICENSE' in f:
                continue
            if driver_name in f:
                return f

        raise Exception(f"Can't find binary for {driver_name} among {files}")

It looks for a file that contains 'chromedriver' in its name. Notice how it already has a check to skip LICENSE.chromedriver, which also lives next to binary.

So fix would be either adding another check to avoid resolving THIRD_PARTY_NOTICES.chromedriver or an improved way to resolve the binary to make sure this issue does not resurface if another file will be added here in future.

DimaYurchenko avatar Jul 24 '24 13:07 DimaYurchenko

+1

mayconfrr avatar Jul 24 '24 14:07 mayconfrr

Seeing the same issue here. drivers.json "binary_path" is pointing to THIRD_PARTY_NOTICES.chromedriver instead of chromedriver.exe

MANT5149 avatar Jul 24 '24 15:07 MANT5149

Seems like new distribution of chromedriver includes THIRD_PARTY_NOTICES.chromedriver next to chromedriver binary.

webdriver_manager.core.driver_cache.DriverCacheManager.__get_binary is failing to resolve the binary correctly

def __get_binary(self, files, driver_name):
        if not files:
            raise Exception(f"Can't find binary for {driver_name} among {files}")

        if len(files) == 1:
            return files[0]

        for f in files:
            if 'LICENSE' in f:
                continue
            if driver_name in f:
                return f

        raise Exception(f"Can't find binary for {driver_name} among {files}")

It looks for a file that contains 'chromedriver' in its name. Notice how it already has a check to skip LICENSE.chromedriver, which also lives next to binary.

So fix would be either adding another check to avoid resolving THIRD_PARTY_NOTICES.chromedriver or an improved way to resolve the binary to make sure this issue does not resurface if another file will be added here in future.

to be on the safe side, wouldn't the following condition be more appropriate: for f in files: if driver_name==f: return f

or when files contains the full path: for f in files: if '/'+driver_name in f: return f

ewagner70 avatar Jul 24 '24 16:07 ewagner70

Just to update @Hasnain-20's answer, I updated his code a bit in case you ran into the "File not found" problem:

if driver_path:
        driver_name = driver_path.split('/')[-1]
        if driver_name != "chromedriver":
            driver_path = "/".join(driver_path.split('/')[:-1] + ["chromedriver.exe"])
            if '/' in driver_path:
                driver_path = driver_path.replace('/', '\\')
            os.chmod(driver_path, 0o755)
    driver = webdriver.Chrome(service=ChromeService(driver_path))

KfirKho avatar Jul 24 '24 17:07 KfirKho

The complete fix should be by adding another skip condition to the for loop in webdriver_manager/core/driver_cache.py/__get_binary():

         for f in files:
            if 'LICENSE' in f:
                continue
            if 'THIRD_PARTY' in f:
                continue
            if driver_name in f:
                return f

If you dont want to edit webdriver_manager lib: you can edit service path before starting the chrome webdriver service:

    service = Service(ChromeDriverManager().install())
    path = service.path
    service.path = path.replace('THIRD_PARTY_NOTICES.', "")
    os.chmod(service.path, 0o755)
    driver = webdriver.Chrome(service=service, options=options)

dmit-tenable avatar Jul 24 '24 20:07 dmit-tenable

So apparently the owner has paused this project for the war in Ukraine, what's the plan? is there somebody else who has permission to merge a PR and publish to PyPi?

shner-elmo avatar Jul 25 '24 00:07 shner-elmo

For people like me that need a guide, we need to update a .py file to add an additional check as there is a new file being added to the chromedriver folder

Windows, navigate to the following folder C:\Users\YOUR_NAME\YOU_VENV_NAME\venv\Lib\site-packages\webdriver_manager\core

or search for 'driver_cache.py' in the C drive

right click the driver_cache.py and open with notepad

change the following text, BE CAREFUL to ensure the indentation stays the same.

for f in files:
            if 'LICENSE' in f:
                continue
            if driver_name in f:
                return f

to

for f in files:
            if 'LICENSE' in f:
                continue
            if 'THIRD_PARTY' in f:
                continue
            if driver_name in f:
                return f

and save the file. the chromedriver should run in your scripts as normal as it did before

sunnyplaza avatar Jul 25 '24 08:07 sunnyplaza

@sunnyplaza The PR has been merged and this fix is in the version available on pypi. You'll need to clear your cache from the last driver.

Jheesbrough avatar Jul 25 '24 08:07 Jheesbrough

Can you please let us know how we can have this fix in a specific version of webdriver ?

ggkiokas avatar Jul 25 '24 13:07 ggkiokas

@ggkiokas could you elaborate? This issue was fixed in #666. Update your version of the webdriver_manager package if you need to use the newer versions of the chrome driver.

Jheesbrough avatar Jul 25 '24 13:07 Jheesbrough

@Jheesbrough oh many thanks. I just saw in the comment of #666 that 4.0.2 is available. I will install it

ggkiokas avatar Jul 25 '24 14:07 ggkiokas

If you just use the latest version of chromedriver.exe, there seems to be no need to use webdriver-manager.

from selenium.webdriver.chrome.webdriver import WebDriver
from selenium.webdriver.chrome.service import Service as ChromeService

driver = WebDriver(service=ChromeService())

moriyaki avatar Jul 28 '24 08:07 moriyaki

Windows Users delete all driver files from .wdm folder and re-run your script

rabbit0057 avatar Jul 30 '24 11:07 rabbit0057

Description The chrome got updated on 23-07-2024 to the version 127.0.6533.72 and so does the chrome_driver. I prepared the new script and downloaded the Chrome Driver via service ChromeDriverManger from webdriver_manager .chrome. and it isn't returning the correct path of the binary. The path returned is mentioned in Error Log section.

The following files were found the downloaded chrome driver binary folder. image

Browser and version: Chrome, version 127.0.6533.72

Operating system and architecture: Linux x64

Selenium version: 4.22.0

WebDriverManager version: 4.0.1

WebDriverManager call:

driver_path = ChromeDriverManager().install()
driver = webdriver.Chrome(service=Service(driver_path))

Error log: image

Solution: I solved the issue by using following piece of code

driver_path = ChromeDriverManager().install()
if driver_path:
    driver_name = driver_path.split('/')[-1]
    if driver_name!="chromedriver":
        driver_path = "/".join(driver_path.split('/')[:-1]+["chromedriver"])
        os.chmod(driver_path, 0o755)
driver = webdriver.Chrome(service=Service(driver_path))

I just wanted to say thank you for sharing! I discovered this last night and have been working on a fix the entire morning. I for sure thought I broke it being new to messing with grid and making changes to my requirements file.

pweev avatar Jul 31 '24 18:07 pweev

driver_path = ChromeDriverManager().install() if driver_path: driver_name = driver_path.split('/')[-1] if driver_name!="chromedriver": driver_path = "/".join(driver_path.split('/')[:-1]+["chromedriver"]) os.chmod(driver_path, 0o755) driver = webdriver.Chrome(service=Service(driver_path))

@pweev Thank you very much for the solution. I needed just a small tweak to make it work on Win since in my case I was still getting the error

    os.chmod(driver_path, 0o755)
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\\Users\\xxx\\.wdm\\drivers\\chromedriver\\win64\\127.0.6533.88\\chromedriver-win32/chromedriver'
driver_path = "/".join(driver_path.split('/')[:-1]+["chromedriver.exe"]).replace('/', '\\')

Pelmen323 avatar Aug 01 '24 08:08 Pelmen323

This issue should be closed @Pelmen323, update your package and clear the driver folder and it will work as intended.

Jheesbrough avatar Aug 01 '24 21:08 Jheesbrough

Removing the arg service from driver = webdriver.Chrome() worked for me too:

from selenium import webdriver

navegador = webdriver.Chrome()

reference: https://stackoverflow.com/a/78802536/10405090

gonultasbu avatar Aug 06 '24 15:08 gonultasbu

chrome_path = ChromeDriverManager().install()
if "THIRD_PARTY_NOTICES.chromedriver" in chrome_path:
    chrome_path = chrome_path.replace("THIRD_PARTY_NOTICES.chromedriver", "chromedriver")

CalebePrates avatar Aug 06 '24 18:08 CalebePrates

This issue should be closed, update your package and clear the driver folder and it will work as intended.

Jheesbrough avatar Aug 06 '24 19:08 Jheesbrough

Confirming that updating the webdriver_manager package fixed this issue on my end.

frederick0291 avatar Aug 08 '24 10:08 frederick0291

chrome_path = ChromeDriverManager().install()
if "THIRD_PARTY_NOTICES.chromedriver" in chrome_path:
    chrome_path = chrome_path.replace("THIRD_PARTY_NOTICES.chromedriver", "chromedriver")

Not working, the error occurred like below:

selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable may have wrong permissions.

Yangeok avatar Sep 30 '24 06:09 Yangeok