Open Hasnain-20 opened 1 month ago
+1
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.
+1
Seeing the same issue here. drivers.json "binary_path" is pointing to THIRD_PARTY_NOTICES.chromedriver instead of chromedriver.exe
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
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))
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)
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?
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 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.
Can you please let us know how we can have this fix in a specific version of webdriver ?
@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 oh many thanks. I just saw in the comment of #666 that 4.0.2 is available. I will install it
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())
Windows Users delete all driver files from .wdm folder and re-run your script
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.
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:
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.
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('/', '\\')
This issue should be closed @Pelmen323, update your package and clear the driver folder and it will work as intended.
Removing the arg service from driver = webdriver.Chrome() worked for me too:
from selenium import webdriver
navegador = webdriver.Chrome()
chrome_path = ChromeDriverManager().install()
if "THIRD_PARTY_NOTICES.chromedriver" in chrome_path:
chrome_path = chrome_path.replace("THIRD_PARTY_NOTICES.chromedriver", "chromedriver")
This issue should be closed, update your package and clear the driver folder and it will work as intended.
Confirming that updating the webdriver_manager
package fixed this issue on my end.
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.
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:
Error log:
Solution: I solved the issue by using following piece of code