I'm running a application using selenium, and I want to know actual chrome browser version installed, before running Chrome Driver to avoid any Exception for compatibility reason. I know I can use driver = webdriver.Chrome("path\\to\\chromedriver.exe")
then driver.capabilities['browserVersion']
to show version but if Chrome Driver version differ from actual chrome browser version that's raise an exception.
Thanks
Edited: Actually I found the answer for myself, the solution I found:
from win32com.client import Dispatch
def get_version_via_com(filename):
parser = Dispatch("Scripting.FileSystemObject")
try:
version = parser.GetFileVersion(filename)
except Exception:
return None
return version
if __name__ == "__main__":
paths = [r"C:\Program Files\Google\Chrome\Application\chrome.exe",
r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"]
version = list(filter(None, [get_version_via_com(p) for p in paths]))[0]
print(version)
# result: 80.0.3987.122
PS: I think people don't understand my question at the beginning and I'm sorry for my english
If you are using selenium, then you can get the chrome browser version using the driver.capabilities
dictionary.
driver.capabilities['browserVersion']
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'])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With