Hello I am looking to update my chrome driver to the latest version but cannot find any information on updating the driver - just info on installing it. What do I need to do to update the driver to the latest version?
Asked
Active
Viewed 4.8k times
6

ouflak
- 2,458
- 10
- 44
- 49

Taryn Antoinette Raines
- 143
- 1
- 3
- 10
-
Checkout this discussion https://stackoverflow.com/questions/49788257/what-is-default-location-of-chromedriver-and-for-installing-chrome-on-windows/49795348#49795348 – undetected Selenium Apr 13 '18 at 19:58
2 Answers
9
Recently I've found that chromedriver
has almost one-to-one version accordance now (there was three-last-releases support policy for chromedriver 2.46
). See version selection guide here: https://sites.google.com/a/chromium.org/chromedriver/downloads/version-selection
I've wrote simple powershell script for updating chromedriver
automatically.
Run this script when you need to update crhomedriver
(like a build step in CI/CD, just before running selenium web tests):
[CmdletBinding()]
param (
[string]$ChromeDir="C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
)
if (-Not (Test-Path $ChromeDir -PathType Leaf)) {
Write-Output "Chrome not found in '$ChromeDir'. Please, install chrome or specify custom chrome location with -ChromeDir argument."
Exit 1
}
$thisScriptRoot = if ($PSScriptRoot -eq "") { "." } else { $PSScriptRoot }
$chromeDriverRelativeDir = "Selenium"
$chromeDriverDir = $(Join-Path $thisScriptRoot $chromeDriverRelativeDir)
$chromeDriverFileLocation = $(Join-Path $chromeDriverDir "chromedriver.exe")
$chromeVersion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($ChromeDir).FileVersion
$chromeMajorVersion = $chromeVersion.split(".")[0]
if (-Not (Test-Path $chromeDriverDir -PathType Container)) {
New-Item -ItemType directory -Path $chromeDriverDir
}
if (Test-Path $chromeDriverFileLocation -PathType Leaf) {
# get version of curent chromedriver.exe
$chromeDriverFileVersion = (& $chromeDriverFileLocation --version)
$chromeDriverFileVersionHasMatch = $chromeDriverFileVersion -match "ChromeDriver (\d+\.\d+\.\d+(\.\d+)?)"
$chromeDriverCurrentVersion = $matches[1]
if (-Not $chromeDriverFileVersionHasMatch) {
Exit
}
}
else {
# if chromedriver.exe not found, will download it
$chromeDriverCurrentVersion = ''
}
if ($chromeMajorVersion -lt 73) {
# for chrome versions < 73 will use chromedriver v2.46 (which supports chrome v71-73)
$chromeDriverExpectedVersion = "2.46"
$chromeDriverVersionUrl = "https://chromedriver.storage.googleapis.com/LATEST_RELEASE"
}
else {
$chromeDriverExpectedVersion = $chromeVersion.split(".")[0..2] -join "."
$chromeDriverVersionUrl = "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_" + $chromeDriverExpectedVersion
}
$chromeDriverLatestVersion = Invoke-RestMethod -Uri $chromeDriverVersionUrl
Write-Output "chrome version: $chromeVersion"
Write-Output "chromedriver version: $chromeDriverCurrentVersion"
Write-Output "chromedriver latest: $chromeDriverLatestVersion"
# will update chromedriver.exe if MAJOR.MINOR.PATCH
$needUpdateChromeDriver = $chromeDriverCurrentVersion -ne $chromeDriverLatestVersion
if ($needUpdateChromeDriver) {
$chromeDriverZipLink = "https://chromedriver.storage.googleapis.com/" + $chromeDriverLatestVersion + "/chromedriver_win32.zip"
Write-Output "Will download $chromeDriverZipLink"
$chromeDriverZipFileLocation = $(Join-Path $chromeDriverDir "chromedriver_win32.zip")
Invoke-WebRequest -Uri $chromeDriverZipLink -OutFile $chromeDriverZipFileLocation
Expand-Archive $chromeDriverZipFileLocation -DestinationPath $(Join-Path $thisScriptRoot $chromeDriverRelativeDir) -Force
Remove-Item -Path $chromeDriverZipFileLocation -Force
$chromeDriverFileVersion = (& $chromeDriverFileLocation --version)
Write-Output "chromedriver updated to version $chromeDriverFileVersion"
}
else {
Write-Output "chromedriver is actual"
}
You can configure relative directory where you need to place chromedriver
with $chromeDriverRelativeDir
variable, relatively of script location.

hal
- 1,705
- 1
- 22
- 28
-
-
-
Then, you don't have to initialize `$dir` here: `if (-Not (Test-Path $chromeDriverDir -PathType Container)) { $dir = New-Item -ItemType directory -Path $chromeDriverDir }` This is redundant, right? – Max Aug 20 '19 at 20:05
-
Yes, I understand now :) I think it was there for debugging purpose. Thanks for pointing out! – hal Aug 22 '19 at 20:04
-
In order to run tests after chrome driver is downloaded and extracted, "update-config.json" file should be updated. It has entries to latest and all browser drivers. `# update update-config.json file with new driver info $updateConfigPath = $(Join-Path $chromeDriverDir "update-config.json") $a = Get-Content $updateConfigPath -raw | ConvertFrom-Json $a.chrome.last = $(Join-Path $chromeDriverDir "chromedriver.exe") $a.chrome.all += $(Join-Path $chromeDriverDir "chromedriver.exe") $a | ConvertTo-Json -depth 32| set-content $updateConfigPath` – sisbilir Feb 20 '20 at 18:59
-
The solution worked great on one machine and failed on another that didn't have any chromedriver installed. I surrounded line started with $chromeVersion with try-catch and it worked great. Try{ $chromeVersion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe").FileVersion } Catch { $chromeVersion = "0.0.0" } – user3638751 Oct 14 '20 at 01:48
-
@user3638751, did you mean case when chrome is not installed on machine, not chromedriver? I've added a check that chrome is installed to script. – hal Oct 19 '20 at 10:34
7
chromedriver is a single self-contained executable file. Just replace your existing version with a newer one.
- download the latest version of chromedriver_win32.zip from https://sites.google.com/a/chromium.org/chromedriver/downloads
- unzip the file to extract chromedriver.exe
- replace your existing file with this new executable.

Corey Goldberg
- 59,062
- 28
- 129
- 143