Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
like image 810
William C Avatar asked Nov 21 '19 16:11

William C


People also ask

Where is Chromedriver exe in Python?

Make sure that the chromedriver.exe file is directly under the PATH you specified, i.e. under C:\chromedriver (or an alternative path). If your zip unpacker created a new folder with a different name inside your specified folder, move the .exe file to that path.


1 Answers

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?

like image 70
Strive Sun Avatar answered Sep 28 '22 06:09

Strive Sun