'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 1:[1]

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

For more details, please refer :https://stackoverflow.com/a/55266105/11128312

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?

Solution 2:[2]

For version 98.0.1108.50 I get the version on Windows by running this in the console:

(you must cd to the directory with the file msedgedriver.exe)

msedgedriver.exe -v

Then I get: MSEdgeDriver 98.0.1108.50 (4203d3deac4b85375d37f4d77d1ffb334a2a6138)

In Python I've not been able to get the driver version but the Browser can be printed like: print("Edge Browser Version: " + self.driver.capabilities['browserVersion'])

Or you can try this:

import subprocess
commands = r"cd ../../ && cd [path to your driver] && msedgedriver.exe -v"
process = subprocess.run(commands, shell=True, check=True, stdout=subprocess.PIPE, universal_newlines=True)
output = process.stdout
print("Chromium Driver Version: " + output)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2