Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 530
leminhnguyen Avatar asked Aug 10 '19 10:08

leminhnguyen


1 Answers

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'])
like image 174
CodeIt Avatar answered Oct 17 '22 18:10

CodeIt