Home > database >  ChromeDriver updated before Chrome did
ChromeDriver updated before Chrome did

Time:03-07

So I have the exact same issue with the question listed here

In that question the issue is that the ChromeDriver is version 99, but Chrome is version 98. The accepted answer states that the Chrome Driver is for a version of Chrome that is "not out yet". I am currently using this code to get the latest release of ChromeDriver

# get the latest chrome driver version number
chrome_url = 'https://chromedriver.storage.googleapis.com/LATEST_RELEASE'
response = requests.get(chrome_url)
version_number = response.text

# build the donwload url
download_url = "https://chromedriver.storage.googleapis.com/"   version_number   "/chromedriver_win32.zip"

is there a way to replace the first section in the code with something that will return the current version of chrome?

CodePudding user response:

I found a way to get it to work, may not be the best way but it works.

def get_version_via_com(filename):
    parser = Dispatch("Scripting.FileSystemObject")
    try:
        v = parser.GetFileVersion(filename)
    except Exception:
        return None
    return v

if __name__ == "__main__":
    # Get Version of Chrome
    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]

    # build the donwload url
    download_url = "https://chromedriver.storage.googleapis.com/"   version   "/chromedriver_win32.zip"

    # download the zip file using the url built above
    latest_driver_zip = wget.download(download_url, 'chromedriver.zip')

    # extract the zip file
    with zipfile.ZipFile(latest_driver_zip, 'r') as zip_ref:
        zip_ref.extractall()  # you can specify the destination folder path here
    # delete the zip file downloaded above
    os.remove(latest_driver_zip)
  • Related