Skip to content

Commit d456414

Browse files
committed
Fix issue with getting browser version from Chrome-for-Testing
1 parent f2b3aee commit d456414

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

seleniumbase/core/detect_b_ver.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -232,25 +232,27 @@ def get_binary_location(browser_type, prefer_chromium=False):
232232
def get_browser_version_from_binary(binary_location):
233233
try:
234234
path = binary_location
235-
if binary_location.count(r"\ ") != binary_location.count(" "):
236-
binary_location = binary_location.replace(" ", r"\ ")
237-
cmd_mapping = binary_location + " --version"
238235
pattern = r"\d+\.\d+\.\d+"
239236
quad_pattern = r"\d+\.\d+\.\d+\.\d+"
240-
quad_version = read_version_from_cmd(cmd_mapping, quad_pattern)
241-
if quad_version and len(str(quad_version)) >= 9: # Eg. 115.0.0.0
242-
return quad_version
243-
version = read_version_from_cmd(cmd_mapping, pattern)
244-
if not version and os_name() == OSType.WIN and os.path.exists(path):
237+
if os_name() == OSType.WIN and os.path.exists(path):
245238
path = path.replace(r"\ ", r" ").replace("\\", "\\\\")
246239
cmd_mapping = (
247-
'''powershell -command "&{(Get-Item '%s')'''
248-
'''.VersionInfo.ProductVersion}"''' % path
240+
'''powershell -command "&{(Get-Command '%s')'''
241+
'''.Version.ToString()}"''' % path
249242
)
250243
quad_version = read_version_from_cmd(cmd_mapping, quad_pattern)
251-
if quad_version and len(str(quad_version)) >= 9:
244+
if quad_version and len(str(quad_version)) >= 9: # Eg. 122.0.0.0
252245
return quad_version
253246
version = read_version_from_cmd(cmd_mapping, pattern)
247+
if version and len(str(version)) >= 7: # Eg. 122.0.0
248+
return version
249+
if binary_location.count(r"\ ") != binary_location.count(" "):
250+
binary_location = binary_location.replace(" ", r"\ ")
251+
cmd_mapping = binary_location + " --version"
252+
quad_version = read_version_from_cmd(cmd_mapping, quad_pattern)
253+
if quad_version and len(str(quad_version)) >= 9:
254+
return quad_version
255+
version = read_version_from_cmd(cmd_mapping, pattern)
254256
return version
255257
except Exception:
256258
return None

0 commit comments

Comments
 (0)