Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChromerDriverManager not returning correct path for the chrome driver #665

Open
Hasnain-20 opened this issue Jul 24, 2024 · 23 comments
Open

Comments

@Hasnain-20
Copy link

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

@mhdzumair
Copy link

+1

@DimaYurchenko
Copy link

DimaYurchenko commented Jul 24, 2024

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.

@mayconfrr
Copy link

+1

@MANT5149
Copy link

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

@ewagner70
Copy link

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

@KfirKho
Copy link

KfirKho commented Jul 24, 2024

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

@dmit-tenable
Copy link

dmit-tenable commented Jul 24, 2024

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)

@shner-elmo
Copy link

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?

@sunnyplaza
Copy link

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

@Jheesbrough
Copy link
Contributor

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

@ggkiokas
Copy link

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

@Jheesbrough
Copy link
Contributor

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

@ggkiokas
Copy link

ggkiokas commented Jul 25, 2024

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

@moriyaki
Copy link

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

@rabbit0057
Copy link

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

@pweev
Copy link

pweev commented Jul 31, 2024

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.

@Pelmen323
Copy link

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('/', '\\')

@Jheesbrough
Copy link
Contributor

Jheesbrough commented Aug 1, 2024

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

@gonultasbu
Copy link

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

@CalebePrates
Copy link

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

@Jheesbrough
Copy link
Contributor

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

@frederick0291
Copy link

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

@Yangeok
Copy link

Yangeok commented Sep 30, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests