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

1

27

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

Maximinamaximize answered 10/8, 2019 at 10:44 Comment(6)
Did you find a solution? If yes, it would be much appreciated it if you share it. Thanks.Touslesmois
@Touslesmois Hi guy, Thank you for understanding my question, the solution was posted you can check now and ask me if there is something need to be clear.Maximinamaximize
Thanks for posting the solution, saved me some time :). In fact, you just need Dispatch: win32com.client.Dispatch.Dispatch("Scripting.FileSystemObject").GetFileVersion(paths[1]), resulted in '80.0.3987.116' in my Win10 box.Touslesmois
@Touslesmois Thanks for correcting me, I have remove netifaces module, because I played around with many tests in one file so I forgot to removed redundant moduleMaximinamaximize
I've added the solution, since I couldn't provide an answer due to thread being closed.Leto
Get this package, this will help you out: link , then call: gc_version = chromedriver_autoinstaller.get_chrome_version() print(gc_version)Irmgard
C
3

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'])
Crosscheck answered 10/8, 2019 at 10:47 Comment(4)
I know that, but when using selenium: driver = webdriver.Chrome("path\\to\\chromedriver.exe") the program can be crashed before running driver.capabilities['version'] (reason is chrome version not compatilble, so I must check chrome version first)Maximinamaximize
@leminhnguyenHUST Are you looking for a method to get current chrome browser version without loading the webdriver ?Crosscheck
Ohh right, I think we can use Python's library likes request, is it feasiable ? (my own opinion)Maximinamaximize
@leminhnguyenHUST That really depends upon your requirement. For this question, i think my answer is sufficient.Crosscheck

© 2022 - 2024 — McMap. All rights reserved.