From d45641459b372ef5d0e72acc0355fa0547a1c7dd Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sat, 16 Mar 2024 11:54:33 -0400 Subject: [PATCH] Fix issue with getting browser version from Chrome-for-Testing --- seleniumbase/core/detect_b_ver.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/seleniumbase/core/detect_b_ver.py b/seleniumbase/core/detect_b_ver.py index 55253bd4..6be629e5 100644 --- a/seleniumbase/core/detect_b_ver.py +++ b/seleniumbase/core/detect_b_ver.py @@ -232,25 +232,27 @@ def get_binary_location(browser_type, prefer_chromium=False): def get_browser_version_from_binary(binary_location): try: path = binary_location + pattern = r"\d+\.\d+\.\d+" + quad_pattern = r"\d+\.\d+\.\d+\.\d+" + if os_name() == OSType.WIN and os.path.exists(path): + path = path.replace(r"\ ", r" ").replace("\\", "\\\\") + cmd_mapping = ( + '''powershell -command "&{(Get-Command '%s')''' + '''.Version.ToString()}"''' % path + ) + quad_version = read_version_from_cmd(cmd_mapping, quad_pattern) + if quad_version and len(str(quad_version)) >= 9: # Eg. 122.0.0.0 + return quad_version + version = read_version_from_cmd(cmd_mapping, pattern) + if version and len(str(version)) >= 7: # Eg. 122.0.0 + return version if binary_location.count(r"\ ") != binary_location.count(" "): binary_location = binary_location.replace(" ", r"\ ") cmd_mapping = binary_location + " --version" - pattern = r"\d+\.\d+\.\d+" - quad_pattern = r"\d+\.\d+\.\d+\.\d+" quad_version = read_version_from_cmd(cmd_mapping, quad_pattern) - if quad_version and len(str(quad_version)) >= 9: # Eg. 115.0.0.0 + if quad_version and len(str(quad_version)) >= 9: return quad_version version = read_version_from_cmd(cmd_mapping, pattern) - if not version and os_name() == OSType.WIN and os.path.exists(path): - path = path.replace(r"\ ", r" ").replace("\\", "\\\\") - cmd_mapping = ( - '''powershell -command "&{(Get-Item '%s')''' - '''.VersionInfo.ProductVersion}"''' % path - ) - quad_version = read_version_from_cmd(cmd_mapping, quad_pattern) - if quad_version and len(str(quad_version)) >= 9: - return quad_version - version = read_version_from_cmd(cmd_mapping, pattern) return version except Exception: return None