Home > Blockchain >  Could not get version for google-chrome with the command: powershell "$ErrorActionPreference=&#
Could not get version for google-chrome with the command: powershell "$ErrorActionPreference=&#

Time:04-30

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

CodePudding user response:

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.

CodePudding user response:

Worked as mentioned after upgrading webdriver-manager and upgrading to the latest python versiom

  • Related