Search code examples
pythonselenium-webdriverwinapiselenium-chromedriverversion

Is it possible to check chromedriver.exe version at runtime in python?


I'm trying to check compatibility of chrome and chromedriver to prompt the user to download the correct chromedriver version if needed. I'm looking to check the version of chrome driver in a way similar to how I check chrome.exe shown below.

from win32api import GetFileVersionInfo
info = GetFileVersionInfo(path/to/chrome.exe)

Solution

  • If I misunderstand anything, please let me know.

    You can use driver. Capabilities ['browserversion '] and driver. Capabilities ['chrome'] ['chromedriverversion ']. Split (' ') [0] to get the version of chrome and chromedriver.

    Then intercept the first 2 digits of the version number for comparison. If they are not the same, you can remind the user to download the correct chromedriver version if needed.

    Minimal example:

    from selenium import webdriver
    
    driver = webdriver.Chrome()
    str1 = driver.capabilities['browserVersion']
    str2 = driver.capabilities['chrome']['chromedriverVersion'].split(' ')[0]
    print(str1)
    print(str2)
    print(str1[0:2])
    print(str2[0:2])
    if str1[0:2] != str2[0:2]: 
      print("please download correct chromedriver version")
    

    Debug:

    enter image description here

    You can also prompt the user with the correct version.

    Chrome and Chromedriver versions as stated on downloads page:

    If you are using Chrome version 114, please download ChromeDriver 114.0.5735.90

    If you are using Chrome version 113, please download ChromeDriver 113.0.5672.63

    ...

    If you are using Chrome version 79, please download ChromeDriver 79.0.3945.36

    If you are using Chrome version 78, please download ChromeDriver 78.0.3904.70

    If you are using Chrome version 77, please download ChromeDriver 77.0.3865.40

    If you are using Chrome version 76, please download ChromeDriver 76.0.3809.126

    If you are using Chrome version 75, please download ChromeDriver 75.0.3770.140

    If you are using Chrome version 74, please download ChromeDriver 74.0.3729.6

    If you are using Chrome version 73, please download ChromeDriver 73.0.3683.68

    For older version of Chrome, please see Barett's anwer

    There is general guide to select version of crhomedriver for specific chrome version: https://sites.google.com/a/chromium.org/chromedriver/downloads/version-selection.

    If you need more chrome version information, please refer: Which ChromeDriver version is compatible with which Chrome Browser version?

    Note:

    Earlier version of chromedriver stored the chrome browser version driver.capabilities['version']. If you want to get chrome browser version without having to worry about this, you can use the below code.

    if 'browserVersion' in driver.capabilities:
        print(driver.capabilities['browserVersion'])
    else:
        print(driver.capabilities['version'])
    

    Links that may be useful to you:

    How to work with a specific version of ChromeDriver while Chrome Browser gets updated automatically through Python selenium

    How can I get Chrome Browser Version running now with Python? [closed]

    Which ChromeDriver version is compatible with which Chrome Browser version?