gpt4 book ai didi

selenium - 如何更新 Windows 10 的 Chrome 驱动程序

转载 作者:行者123 更新时间:2023-12-01 12:13:43 26 4
gpt4 key购买 nike

关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。












想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。

去年关闭。




Improve this question




您好,我想将我的 chrome 驱动程序更新到最新版本,但 Ant 找到有关更新驱动程序的任何信息,只是有关安装它的信息。我需要做什么才能将驱动程序更新到最新版本?

最佳答案

最近我发现chromedriver现在几乎是一对一的版本(chromedriver 2.46 有最后三个版本的支持策略)。请参阅此处的版本选择指南:https://sites.google.com/a/chromium.org/chromedriver/downloads/version-selection
我已经 wrote simple powershell script用于更新 chromedriver自动地。
需要更新时运行此脚本 crhomedriver (就像 CI/CD 中的构建步骤,就在运行 selenium Web 测试之前):

[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"
}
您可以配置需要放置的相对目录 chromedriver$chromeDriverRelativeDir变量,相对于脚本位置。

关于selenium - 如何更新 Windows 10 的 Chrome 驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49824109/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com