@@ -141,6 +141,18 @@ def _repair_chromedriver(chrome_options, headless_options):
141
141
return
142
142
143
143
144
+ def _repair_edgedriver (edge_version ):
145
+ import subprocess
146
+
147
+ print (
148
+ "\n Warning: msedgedriver version doesn't match Edge version!"
149
+ "\n Attempting to install a matching version of msedgedriver:" )
150
+ subprocess .check_call (
151
+ "sbase install edgedriver %s" % edge_version , shell = True
152
+ )
153
+ return
154
+
155
+
144
156
def _mark_chromedriver_repaired ():
145
157
import codecs
146
158
@@ -1399,17 +1411,81 @@ def get_local_driver(
1399
1411
edge_options .add_argument (chromium_arg_item )
1400
1412
if selenium4 :
1401
1413
warnings .simplefilter ("ignore" , category = DeprecationWarning )
1402
- return Edge (
1403
- executable_path = LOCAL_EDGEDRIVER ,
1404
- options = edge_options ,
1405
- )
1414
+ try :
1415
+ driver = Edge (
1416
+ executable_path = LOCAL_EDGEDRIVER ,
1417
+ options = edge_options ,
1418
+ )
1419
+ except Exception as e :
1420
+ auto_upgrade_edgedriver = False
1421
+ if "This version of MSEdgeDriver only supports" in e .msg :
1422
+ if "Current browser version is " in e .msg :
1423
+ auto_upgrade_edgedriver = True
1424
+ if not auto_upgrade_edgedriver :
1425
+ raise Exception (e .msg ) # Not an obvious fix. Raise.
1426
+ else :
1427
+ pass # Try upgrading EdgeDriver to match Edge.
1428
+ edge_version = e .msg .split (
1429
+ "Current browser version is " )[1 ].split (' ' )[0 ]
1430
+ args = " " .join (sys .argv )
1431
+ if ("-n" in sys .argv or " -n=" in args or args == "-c" ):
1432
+ import fasteners
1433
+
1434
+ edgedriver_fixing_lock = fasteners .InterProcessLock (
1435
+ constants .MultiBrowser .CHROMEDRIVER_FIXING_LOCK
1436
+ )
1437
+ with edgedriver_fixing_lock :
1438
+ if not _was_chromedriver_repaired (): # Works for Edge
1439
+ _repair_edgedriver (edge_version )
1440
+ _mark_chromedriver_repaired () # Works for Edge
1441
+ else :
1442
+ if not _was_chromedriver_repaired (): # Works for Edge
1443
+ _repair_edgedriver (edge_version )
1444
+ _mark_chromedriver_repaired () # Works for Edge
1445
+ driver = Edge (
1446
+ executable_path = LOCAL_EDGEDRIVER ,
1447
+ options = edge_options ,
1448
+ )
1449
+ return driver
1406
1450
else :
1407
1451
capabilities = edge_options .to_capabilities ()
1408
1452
capabilities ["platform" ] = ""
1409
- return Edge (
1410
- executable_path = LOCAL_EDGEDRIVER ,
1411
- capabilities = capabilities ,
1412
- )
1453
+ try :
1454
+ driver = Edge (
1455
+ executable_path = LOCAL_EDGEDRIVER ,
1456
+ capabilities = capabilities ,
1457
+ )
1458
+ except Exception as e :
1459
+ auto_upgrade_edgedriver = False
1460
+ if "This version of MSEdgeDriver only supports" in e .msg :
1461
+ if "Current browser version is " in e .msg :
1462
+ auto_upgrade_edgedriver = True
1463
+ if not auto_upgrade_edgedriver :
1464
+ raise Exception (e .msg ) # Not an obvious fix. Raise.
1465
+ else :
1466
+ pass # Try upgrading EdgeDriver to match Edge.
1467
+ edge_version = e .msg .split (
1468
+ "Current browser version is " )[1 ].split (' ' )[0 ]
1469
+ args = " " .join (sys .argv )
1470
+ if ("-n" in sys .argv or " -n=" in args or args == "-c" ):
1471
+ import fasteners
1472
+
1473
+ edgedriver_fixing_lock = fasteners .InterProcessLock (
1474
+ constants .MultiBrowser .CHROMEDRIVER_FIXING_LOCK
1475
+ )
1476
+ with edgedriver_fixing_lock :
1477
+ if not _was_chromedriver_repaired (): # Works for Edge
1478
+ _repair_edgedriver (edge_version )
1479
+ _mark_chromedriver_repaired () # Works for Edge
1480
+ else :
1481
+ if not _was_chromedriver_repaired (): # Works for Edge
1482
+ _repair_edgedriver (edge_version )
1483
+ _mark_chromedriver_repaired () # Works for Edge
1484
+ driver = Edge (
1485
+ executable_path = LOCAL_EDGEDRIVER ,
1486
+ capabilities = capabilities ,
1487
+ )
1488
+ return driver
1413
1489
elif browser_name == constants .Browser .SAFARI :
1414
1490
arg_join = " " .join (sys .argv )
1415
1491
if ("-n" in sys .argv ) or (" -n=" in arg_join ) or (arg_join == "-c" ):
@@ -1628,7 +1704,46 @@ def get_local_driver(
1628
1704
else : # Running headless on Linux
1629
1705
try :
1630
1706
return webdriver .Chrome (options = chrome_options )
1631
- except Exception :
1707
+ except Exception as e :
1708
+ auto_upgrade_chromedriver = False
1709
+ if "This version of ChromeDriver only supports" in e .msg :
1710
+ auto_upgrade_chromedriver = True
1711
+ elif "Chrome version must be between" in e .msg :
1712
+ auto_upgrade_chromedriver = True
1713
+ if auto_upgrade_chromedriver :
1714
+ args = " " .join (sys .argv )
1715
+ if (
1716
+ "-n" in sys .argv
1717
+ or " -n=" in args
1718
+ or args == "-c"
1719
+ ):
1720
+ import fasteners
1721
+
1722
+ chromedr_fixing_lock = fasteners .InterProcessLock (
1723
+ constants .MultiBrowser .CHROMEDRIVER_FIXING_LOCK
1724
+ )
1725
+ with chromedr_fixing_lock :
1726
+ if not _was_chromedriver_repaired ():
1727
+ try :
1728
+ _repair_chromedriver (
1729
+ chrome_options , chrome_options
1730
+ )
1731
+ _mark_chromedriver_repaired ()
1732
+ except Exception :
1733
+ pass
1734
+ else :
1735
+ if not _was_chromedriver_repaired ():
1736
+ try :
1737
+ _repair_chromedriver (
1738
+ chrome_options , chrome_options
1739
+ )
1740
+ except Exception :
1741
+ pass
1742
+ _mark_chromedriver_repaired ()
1743
+ try :
1744
+ return webdriver .Chrome (options = chrome_options )
1745
+ except Exception :
1746
+ pass
1632
1747
# Use the virtual display on Linux during headless errors
1633
1748
logging .debug (
1634
1749
"\n Warning: Chrome failed to launch in"
0 commit comments