@@ -232,25 +232,27 @@ def get_binary_location(browser_type, prefer_chromium=False):
232
232
def get_browser_version_from_binary (binary_location ):
233
233
try :
234
234
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"
238
235
pattern = r"\d+\.\d+\.\d+"
239
236
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 ):
245
238
path = path .replace (r"\ " , r" " ).replace ("\\ " , "\\ \\ " )
246
239
cmd_mapping = (
247
- '''powershell -command "&{(Get-Item '%s')'''
248
- '''.VersionInfo.ProductVersion }"''' % path
240
+ '''powershell -command "&{(Get-Command '%s')'''
241
+ '''.Version.ToString() }"''' % path
249
242
)
250
243
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
252
245
return quad_version
253
246
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 )
254
256
return version
255
257
except Exception :
256
258
return None
0 commit comments