Programmatically determine chrome browser version regardless of OS

  • My problem is chromedriver 78 (currently the latest) doesn't work with Chrome 77. Ubuntu still has 77 in the apt-get repo for google-chrome-stable. My regression script automatically pulls down the latest available chromedriver (unless you specifcally give it a version) which is currently 78. I want to add in some logic to my regression to check what version of Chrome is currently installed and automatically grab the appropriate chromedriver version. The regression has the ability to run on mac, linux or windows.

    I have been trying to figure out how selenium (or the chromedriver) knows where the browser is installed. It seems to always just 'know'. Which would imply there is some way to automatically determine the location of the browser? If I had that, I would be able to call --version. But I can't for the life of me, figure out how to determine where chrome is installed (programmatically, anyway).

    Is there a way to programmatically determine what the chrome version is for a given OS?

  • It turns out the reason chromedriver knows where chrome is installed is it looks for it in the default installation locations. See chromedriver requirements enter image description here

    I ended up using writing this script.

    def chrome_version():
        osname = platform.system()
        if osname == 'Darwin':
            installpath = "/Applications/Google\\ Chrome"
        elif osname == 'Windows':
            installpath = "C:\Program Files\Google\Chrome\Application\chrome.exe"
        elif osname == 'Linux':
            installpath = "/usr/bin/google-chrome"
            raise NotImplemented(f"Unknown OS '{osname}'")
        verstr = os.popen(f"{installpath} --version").read().strip('Google Chrome ').strip()
        return verstr

    note: it appears the chromedriver documentation is a little out of date with the windows install location

Suggested Topics