Recently I ran into an issue, my chrome version is 122.0.6261.95 but when I tried to find chrome driver for 122.0.6261.95 it was not available. Closest one available was 122.0.6261.94. So I downloaded 122.0.6261.94, chromedriver zip file, extracted it, and put both the files chromedriver.exe and Lisence.chromedriver in the Python root directory.

Issue: Mismatched ChromeDriver.exe Version

As soon as I hit entered I ran into this issue:

Traceback (most recent call last): File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\common\driver_finder.py", line 38, in get_path path = SeleniumManager().driver_location(options) if path is None else path ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\common\selenium_manager.py", line 90, in driver_location output = self.run(args) ^^^^^^^^^^^^^^ File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\common\selenium_manager.py", line 138, in run raise WebDriverException(f"Unsuccessful command executed: {command}.\n{result}{stderr}") selenium.common.exceptions.WebDriverException: Message: Unsuccessful command executed: C:\Users\user\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\common\windows\selenium-manager.exe --browser chrome --output json. {'code': 69, 'message': 'Driver unavailable: Driver path: ', 'driver_path': '', 'browser_path': ''}

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "c:\Users\user\Desktop\�꒵����\��ũ�Ѹ�\insta\app.py", line 6, in driver = webdriver.Chrome() ^^^^^^^^^^^^^^^^^^ File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\chrome\webdriver.py", line 45, in init super().init( File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\chromium\webdriver.py", line 51, in init self.service.path = DriverFinder.get_path(self.service, options) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\user\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\common\driver_finder.py", line 41, in get_path raise NoSuchDriverException(msg) from err selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain driver for chrome using Selenium Manager.; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location

Upon close inspection I came to know this is because of mismatched chromedriver.exe version it is throwing error.

Solution: Automatically fetch chromedriver.exe and add it to the program

There is something called webdriver-manager it manages your all of your webdriver.

How to install webdriver-manager?

You can easily use the pip command. Run the below command to install the webdrver-manager.

pip install webdriver-manager

Now, fetch the chromedriver.exe using webdriver-manager and pass it to the program. Refer to the below code snippet ????.

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

driver=webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
Make sure you are using Selenium 4. Webdriver-manager only works for Selenium 4

Categorized in: