Selenium 如何为windows 10更新chrome驱动程序

Selenium 如何为windows 10更新chrome驱动程序,selenium,windows-10,selenium-chromedriver,python-3.5,Selenium,Windows 10,Selenium Chromedriver,Python 3.5,您好,我正在寻找更新我的chrome驱动程序到最新版本,但ant找到任何关于更新驱动程序的信息只是安装信息。如何将驱动程序更新为最新版本?chromedriver是一个独立的可执行文件。只需将现有版本替换为新版本即可 从下载最新版本的chromedriver_win32.zip 解压缩文件以提取chromedriver.exe 用此新的可执行文件替换现有文件 最近我发现chromedriver现在几乎有一对一的版本一致性(最近有三个版本支持chromedriver 2.46)。请参见此处的版本选

您好,我正在寻找更新我的chrome驱动程序到最新版本,但ant找到任何关于更新驱动程序的信息只是安装信息。如何将驱动程序更新为最新版本?

chromedriver是一个独立的可执行文件。只需将现有版本替换为新版本即可

  • 从下载最新版本的chromedriver_win32.zip
  • 解压缩文件以提取chromedriver.exe
  • 用此新的可执行文件替换现有文件

  • 最近我发现
    chromedriver
    现在几乎有一对一的版本一致性(最近有三个版本支持
    chromedriver 2.46
    )。请参见此处的版本选择指南:

    我已经准备好自动更新
    chromedriver

    当需要更新
    crhomedriver
    时运行此脚本(就像在运行selenium web测试之前的CI/CD中的构建步骤):

    [CmdletBinding()]
    param(
    [string]$ChromeDir=“C:\ProgramFiles(x86)\Google\Chrome\Application\Chrome.exe”
    )
    if(-Not(测试路径$ChromeDir-路径类型叶)){
    写入输出“Chrome未在“$ChromeDir”中找到。请安装Chrome或使用-ChromeDir参数指定自定义Chrome位置。”
    出口1
    }
    $thisScriptRoot=if($PSScriptRoot-eq“”){“}否则{$PSScriptRoot}
    $chromeDriverRelativeDir=“硒”
    $chromeDriverDir=$(连接路径$thisScriptRoot$chromeDriverRelativeDir)
    $chromeDriverFileLocation=$(连接路径$chromeDriverDir“chromedriver.exe”)
    $chromeVersion=[System.Diagnostics.FileVersionInfo]::GetVersionInfo($ChromeDir).FileVersion
    $ChromeMarVersion=$chromeVersion.split(“.”[0]
    if(-Not(测试路径$chromeDriverDir-PathType容器)){
    新项目-项目类型目录-路径$chromeDriverDir
    }
    if(测试路径$chromeDriverFileLocation-路径类型叶){
    #获取curent chromedriver.exe的版本
    $chromeDriverFileVersion=(&$chromeDriverFileLocation--version)
    $chromeDriverFileVersionHasMatch=$chromeDriverFileVersion-匹配“ChromeDriver(\d+\.\d+\.\d+)(\.\d+)”
    $chromeDriverCurrentVersion=$matches[1]
    if(-Not$chromeDriverFileVersionHasMatch){
    出口
    }
    }
    否则{
    #如果找不到chromedriver.exe,将下载它
    $chromeDriverCurrentVersion=''
    }
    如果($chromeMajorVersion-lt 73){
    #对于<73的chrome版本,将使用chromedriver v2.46(支持ChromeV71-73)
    $chromeDriverExpectedVersion=“2.46”
    $chromeDriverVersionUrl=”https://chromedriver.storage.googleapis.com/LATEST_RELEASE"
    }
    否则{
    $chromeDriverExpectedVersion=$chromeVersion.split(“.”[0..2]-join“
    $chromeDriverVersionUrl=”https://chromedriver.storage.googleapis.com/LATEST_RELEASE_“+$ChromeDriveredExpectedVersion
    }
    $chromeDriverLatestVersion=调用RestMethod-Uri$chromeDriverVersionUrl
    写入输出“chrome版本:$chromeVersion”
    写入输出“chromedriver版本:$chromedriver当前版本”
    写入输出“chromedriver最新版本:$chromedriver最新版本”
    #如果出现MAJOR.MINOR.PATCH,将更新chromedriver.exe
    $needUpdateChromeDriver=$chromeDriverCurrentVersion-ne$chromeDriverLatestVersion
    如果($needUpdateChromeDriver){
    $chromeDriverZipLink=”https://chromedriver.storage.googleapis.com/“+$chromeDriverLatestVersion+”/chromedriverwin32.zip”
    写入输出“将下载$chromeDriverZipLink”
    $chromeDriverZipFileLocation=$(连接路径$chromeDriverDir“chromedriverwin32.zip”)
    调用WebRequest-Uri$chromeDriverZipLink-OutFile$chromeDriverZipFileLocation
    展开存档$chromeDriverZipFileLocation-DestinationPath$(加入路径$thisScriptRoot$chromeDriverRelativeDir)-强制
    移除项目-路径$chromeDriverZipFileLocation-强制
    $chromeDriverFileVersion=(&$chromeDriverFileLocation--version)
    写入输出“chromedriver更新为版本$chromeDriverFileVersion”
    }
    否则{
    写入输出“chromedriver是实际的”
    }
    

    您可以使用
    $chromeDriverRelativeDir
    变量(相对于脚本位置)配置需要放置
    chromeDriverRelativeDir
    的相对目录。

    签出此讨论您在脚本中的任何位置都不使用
    $dir
    。为什么我需要使用$dir?我使用了$PSScriptRoot,然后,您不必在这里初始化
    $dir
    如果(-Not(Test Path$chromeDriverDir-PathType Container)){$dir=New Item-ItemType directory-Path$chromeDriverDir}
    这是多余的,对吗?是的,我现在明白了:)我认为它是为了调试目的而存在的。谢谢你的指点!为了在下载并提取chrome驱动程序后运行测试,应该更新“update config.json”文件。它包含最新和所有浏览器驱动程序的条目<代码>#使用新驱动程序信息更新update-config.json文件$updateConfigPath=$(连接路径$chromeDriverDir“update config.json”)$a=Get Content$updateConfigPath-raw | ConvertFrom json$a.chrome.last=$(连接路径$chromeDriverDir“chromedriver.exe”)$a.chrome.all+=$(连接路径$chromeDriverDir“chromedriver.exe”)$a |转换为Json-深度32 |设置内容$updateConfigPath