Matching between Chrome driver and chrome version of python selenium

Many users using selenium will encounter a problem. Our chromedriver is often incompatible with the local Chrome browser version, resulting in the failure of instantiating webdriver.Chrome. The error information is as follows:

An exception occurred: SessionNotCreatedException
 Message: session not created: This version of ChromeDriver only supports Chrome version 90 Current browser version is 95.0.4638.69 with binary path C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

Small climb in the previous blog( Compatibility between chrome and chromedriver versions of python selenium automation ), it encapsulates the method to obtain the chrome version and the chromedriver version respectively. When the major version numbers of the two versions are different, they are automatically networked in the Taobao source warehouse: ChromeDriver Mirror ( Download the corresponding version of chromedriver in to realize the automatic update of chromedriver based on requirements, so that the two can match for a long time.

In fact, after some exploration, Xiaobo found that there was a third-party professional python library webdriver_manager gracefully solves this problem, and its background update chromedriver uses Google's official chromedriver warehouse. This URL( )It can be accessed normally in China. The biggest advantage over Taobao source warehouse is that it always has the latest version of chrome driver, and the warehouse is updated faster, as shown in the figure below:


In fact, the webdriver manager Library (installed via PIP install webdriver manager) can also be used to update edgecorniumdriver, GeckoDriver, IEDriver and OperaDriver files. How to do this? In fact, we only need two or three lines of code when executing:

driver = webdriver.Chrome(executable_path=driver_path)
Of course, if we have more exploration spirit, we might as well take a look at its source code to understand its essence. The source code of ChromeDriverManager class is as follows:
class ChromeDriverManager(DriverManager):
    def __init__(self, version="latest",
        super().__init__(path, log_level=log_level, print_first_line=print_first_line,

        self.driver = ChromeDriver(name=name,

    def install(self):
        log(f"Current {self.driver.chrome_type} version is {self.driver.browser_version}", first_line=True)
        driver_path = self._get_driver_path(self.driver)

        os.chmod(driver_path, 0o755)
        return driver_path

The source code of the chromedriver class is as follows:

class ChromeDriver(Driver):
    def __init__(self, name, version, os_type, url, latest_release_url,
        super(ChromeDriver, self).__init__(name, version, os_type, url,
        self.chrome_type = chrome_type
        self.browser_version = get_browser_version_from_os(chrome_type)

    def get_os_type(self):
        if "win" in super().get_os_type():
            return "win32"
        return super().get_os_type()

    def get_latest_release_version(self):
        log(f"Get LATEST driver version for {self.browser_version}")
        resp = requests.get(f"{self._latest_release_url}_{self.browser_version}")
        return resp.text.rstrip()

This method will call the find_driver method of DriverCache class by default:

    def find_driver(self, browser_version, driver_name, os_type, driver_version):
        metadata = self.get_metadata()

        key = f"{os_type}_{driver_name}_{driver_version}_for_{browser_version}"
        if key not in metadata:
            log(f"There is no [{os_type}] {driver_name} for browser {browser_version} in cache")
            return None

        driver_info = metadata[key]

        if not self.__is_valid(driver_info):
            return None

        path = driver_info['binary_path']
        log(f"Driver [{path}] found in cache")
        return path

If the system can find the driver of the corresponding version in a specific path, it can call it directly. Otherwise, call the get_latest_release_version method to get the latest driver online and put it in the corresponding system path. For example, the latest version of chromedriver on my computer is uniformly stored in the path shown in the figure below for reference:





  Due to the automatic upgrade strategy of computer-side Chrome browser, the local chrome river is always not compatible in time. If you have such problems, don't you try it quickly?

Tags: Python Selenium

Posted on Mon, 08 Nov 2021 15:13:45 -0500 by andylyon87