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

4

14

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)
Everett answered 21/11, 2019 at 16:18 Comment(3)
Is your code running inside the chromedriver.exe process?Brawny
My apologies I'm not sure i understand your question. I was able to accomplish this with the following: driver = webdriver.Chrome() driver.capabilities['chrome']['chromedriverVersion'].split(' ')[0] Sorry I also cannot figure out how to get code to continue on a new line even after reading the help..Everett
It is a strange property of Chromedriver.exe that it never has a version number on it like most Windows dlls and exesMcgray
G
23

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?

Gossipry answered 22/11, 2019 at 6:57 Comment(0)
F
0

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)
Felker answered 14/4, 2022 at 20:45 Comment(0)
D
0

With the code below, you can check the version of chromedriver at runtime in Python:

from selenium import webdriver

driver = webdriver.Chrome()
print(driver.capabilities['browserVersion']) # 115.0.5790.171
Dorrie answered 15/8, 2023 at 17:41 Comment(0)
M
-1

for Edge use

driver = webdriver.Edge(options=options,service=Service(driver_path))

driver.capabilities['msedge']['msedgedriverVersion'].split(' ')[0]

Montane answered 18/9, 2022 at 6:6 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Lamere

© 2022 - 2024 — McMap. All rights reserved.