用命令无法获得Google-Chrome的版本:PowerShell; powerShell; erroractionPreference =' sillysyContinue'将WebDrivermanager与硒一起使用

发布于 2025-01-24 15:46:56 字数 1168 浏览 0 评论 0 原文

在使用Selenium和Chrome Driver运行Python脚本时,我会在下面遇到错误。

我使用所讨论的脚本进行一些非常简单的自动化在本地运行(Win 10)。 由于WebDridver无法获得Chrome版本,因此它安装了最新版本,导致脚本在Chrome具有更新时经常失败,但尚未安装。

====== WebDriver manager ======
Could not get version for google-chrome with the command:  powershell "$ErrorActionPreference='silentlycontinue' ; (Get-Item -Path "$env:PROGRAMFILES\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion ; if (-not $? -or $? -match $error) { (Get-Item -Path "$env:PROGRAMFILES(x86)\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion } if (-not $? -or $? -match $error) { (Get-Item -Path "$env:LOCALAPPDATA\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion } if (-not $? -or $? -match $error) { reg query "HKCU\SOFTWARE\Google\Chrome\BLBeacon" /v version } if (-not $? -or $? -match $error) { reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome" /v version }"
Current google-chrome version is UNKNOWN
Get LATEST chromedriver version for UNKNOWN google-chrome
Trying to download new driver from https://chromedriver.storage.googleapis.com/101.0.4951.41/chromedriver_win32.zip

When running a python script with selenium and chrome driver I am getting the error below.

I use the script in question for some a pretty simple automation running locally (win 10).
Since the webdridver is unable to get the Chrome version it installs the latest version, causing the script to fail frequently when chrome has an update but it was not yet installed.

====== WebDriver manager ======
Could not get version for google-chrome with the command:  powershell "$ErrorActionPreference='silentlycontinue' ; (Get-Item -Path "$env:PROGRAMFILES\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion ; if (-not $? -or $? -match $error) { (Get-Item -Path "$env:PROGRAMFILES(x86)\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion } if (-not $? -or $? -match $error) { (Get-Item -Path "$env:LOCALAPPDATA\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion } if (-not $? -or $? -match $error) { reg query "HKCU\SOFTWARE\Google\Chrome\BLBeacon" /v version } if (-not $? -or $? -match $error) { reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome" /v version }"
Current google-chrome version is UNKNOWN
Get LATEST chromedriver version for UNKNOWN google-chrome
Trying to download new driver from https://chromedriver.storage.googleapis.com/101.0.4951.41/chromedriver_win32.zip

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三生一梦 2025-01-31 15:46:56

此错误消息...

====== WebDriver manager ======
Could not get version for google-chrome with the command:  powershell "$ErrorActionPreference='silentlycontinue' ; (Get-Item -Path "$env:PROGRAMFILES\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion ; if (-not $? -or $? -match $error) { (Get-Item -Path "$env:PROGRAMFILES(x86)\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion } if (-not $? -or $? -match $error) { (Get-Item -Path "$env:LOCALAPPDATA\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion } if (-not $? -or $? -match $error) { reg query "HKCU\SOFTWARE\Google\Chrome\BLBeacon" /v version } if (-not $? -or $? -match $error) { reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome" /v version }"
Current google-chrome version is UNKNOWN
Get LATEST chromedriver version for UNKNOWN google-chrome
Trying to download new driver from https://chromedriver.storage.googleapis.com/101.0.4951.41/chromedriver_win32.zip

...表示 webdriver-manager 无法检测到 google-chrome 浏览器的版本使用以下任何一个命令:

  1. (get -item -path“ $ env:programFiles \ google \ chrome \ chrome \ application \ chrome.exe”)
  2. 。 > (get -item-path“ $ env:programFiles(x86)\ google \ chrome \ chrome \ application \ chrome.exe”)
  3. 。 \ chrome \ application \ chrome.exe”)。
  4. -Item -path“ $ env:localappdata \ google \ chrome BlbeAcon“/v版本
  5. reg QUERY”

深度潜水

该问题似乎是以下任务:

  • PowerShell脚本中的一个额外纽线
  • 丢失了带有programFiles(x86)的ENV空间(x86)
  • 向PowerShell命令 -execution -ececution -ececution -ececution -ececution -ececution -ececution -ececution -ececution -ececution -bypass -nologo -nonInteractive -noprofile -command
  • 用四个doublequotes替换单个双重

在拉的某个时候 试标

最后,解决方案是修复powershell的确定和str CONSATINATION ://github.com/sergeypirogov/webdriver_manager/blob/352bd0ba13e5097935472f978f978f33bbbb908c9c3c3d6d6d6d6d6d/webdriver_manager/utils.manager/utils.py#l147

def windows_browser_apps_to_cmd(*apps: str) -> str:
    """Create analogue of browser --version command for windows.
    From browser paths and registry keys.
    Result command example:
       cmd1; if (-not $? -or $? -match $error) { cmd2 }
    """
    ignore_errors_cmd_part = ' 2>$null' if os.getenv('WDM_LOG_LEVEL') == '0' else ''
    powershell = determine_powershell()

    script = (
    "$ErrorActionPreference='silentlycontinue' ; "
    + f'{apps[0]}{ignore_errors_cmd_part} ;'
    + ''.join(f" if (-not $? -or $? -match $error) {{ {i}{ignore_errors_cmd_part} }}" for i in apps[1:])
    )

更新

到当前 可以解决问题。

This error message...

====== WebDriver manager ======
Could not get version for google-chrome with the command:  powershell "$ErrorActionPreference='silentlycontinue' ; (Get-Item -Path "$env:PROGRAMFILES\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion ; if (-not $? -or $? -match $error) { (Get-Item -Path "$env:PROGRAMFILES(x86)\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion } if (-not $? -or $? -match $error) { (Get-Item -Path "$env:LOCALAPPDATA\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion } if (-not $? -or $? -match $error) { reg query "HKCU\SOFTWARE\Google\Chrome\BLBeacon" /v version } if (-not $? -or $? -match $error) { reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome" /v version }"
Current google-chrome version is UNKNOWN
Get LATEST chromedriver version for UNKNOWN google-chrome
Trying to download new driver from https://chromedriver.storage.googleapis.com/101.0.4951.41/chromedriver_win32.zip

...implies that webdriver-manager was unable to detect the version of the browser using either of the following commands:

  1. (Get-Item -Path "$env:PROGRAMFILES\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion
  2. (Get-Item -Path "$env:PROGRAMFILES(x86)\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion
  3. (Get-Item -Path "$env:LOCALAPPDATA\Google\Chrome\Application\chrome.exe").VersionInfo.FileVersion
  4. reg query "HKCU\SOFTWARE\Google\Chrome\BLBeacon" /v version
  5. reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome" /v version

Deep Dive

This issue was discussed in google-chrome version is UNKNOWN with webdriver_manager 3.5.3 (Win) where the issue appeared to be either of the following:

  • An extra newline in the powershell script
  • Missing space for env with PROGRAMFILES (x86)
  • Add a couple of flags to the powershell command -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -Command
  • Replacing single doublequotes with four doublequotes

At some point in the pull request base64 encode powershell commands appeared base64 encoding was necessary.

Finally the fix was to fix powershell determination and str concatenation in webdriver_manager/utils.py:

def windows_browser_apps_to_cmd(*apps: str) -> str:
    """Create analogue of browser --version command for windows.
    From browser paths and registry keys.
    Result command example:
       cmd1; if (-not $? -or $? -match $error) { cmd2 }
    """
    ignore_errors_cmd_part = ' 2>$null' if os.getenv('WDM_LOG_LEVEL') == '0' else ''
    powershell = determine_powershell()

    script = (
    "$ErrorActionPreference='silentlycontinue' ; "
    + f'{apps[0]}{ignore_errors_cmd_part} ;'
    + ''.join(f" if (-not $? -or $? -match $error) {{ {i}{ignore_errors_cmd_part} }}" for i in apps[1:])
    )

Solution

Update to current webdriver-manager version v3.5.4 which would solve the issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文