@@ -116,11 +116,18 @@ def is_headless_iedriver_on_path():
116
116
return os .path .exists (LOCAL_HEADLESS_IEDRIVER )
117
117
118
118
119
- def _repair_chromedriver (chrome_options , headless_options ):
119
+ def _repair_chromedriver (chrome_options , headless_options , mcv = None ):
120
120
import subprocess
121
121
122
+ if mcv :
123
+ subprocess .check_call (
124
+ "sbase install chromedriver %s" % mcv , shell = True
125
+ )
126
+ return
122
127
driver = None
123
- subprocess .check_call ("sbase install chromedriver 2.44" , shell = True )
128
+ subprocess .check_call (
129
+ "sbase install chromedriver 72.0.3626.69" , shell = True
130
+ )
124
131
try :
125
132
if selenium4 :
126
133
service = ChromeService (executable_path = LOCAL_CHROMEDRIVER )
@@ -149,7 +156,10 @@ def _repair_chromedriver(chrome_options, headless_options):
149
156
chromedriver_ver = chrome_dict ["chromedriverVersion" ]
150
157
chromedriver_ver = chromedriver_ver .split (" " )[0 ]
151
158
major_chromedriver_ver = chromedriver_ver .split ("." )[0 ]
152
- if major_chromedriver_ver != major_chrome_ver :
159
+ if (
160
+ major_chromedriver_ver != major_chrome_ver
161
+ and int (major_chrome_ver ) >= 73
162
+ ):
153
163
subprocess .check_call (
154
164
"sbase install chromedriver %s" % major_chrome_ver , shell = True
155
165
)
@@ -169,12 +179,12 @@ def _repair_edgedriver(edge_version):
169
179
return
170
180
171
181
172
- def _mark_chromedriver_repaired ():
182
+ def _mark_driver_repaired ():
173
183
import codecs
174
184
175
185
abs_path = os .path .abspath ("." )
176
- chromedriver_repaired_lock = constants .MultiBrowser .CHROMEDRIVER_REPAIRED
177
- file_path = os .path .join (abs_path , chromedriver_repaired_lock )
186
+ driver_repaired_lock = constants .MultiBrowser .DRIVER_REPAIRED
187
+ file_path = os .path .join (abs_path , driver_repaired_lock )
178
188
downloads_folder = download_helper .get_downloads_folder ()
179
189
if not os .path .exists (downloads_folder ):
180
190
os .makedirs (downloads_folder )
@@ -183,10 +193,10 @@ def _mark_chromedriver_repaired():
183
193
out_file .close ()
184
194
185
195
186
- def _was_chromedriver_repaired ():
196
+ def _was_driver_repaired ():
187
197
abs_path = os .path .abspath ("." )
188
- chromedriver_repaired_lock = constants .MultiBrowser .CHROMEDRIVER_REPAIRED
189
- file_path = os .path .join (abs_path , chromedriver_repaired_lock )
198
+ driver_repaired_lock = constants .MultiBrowser .DRIVER_REPAIRED
199
+ file_path = os .path .join (abs_path , driver_repaired_lock )
190
200
return os .path .exists (file_path )
191
201
192
202
@@ -1400,18 +1410,33 @@ def get_local_driver(
1400
1410
" executable: %s" % e
1401
1411
)
1402
1412
elif not is_geckodriver_on_path ():
1413
+ from seleniumbase .console_scripts import sb_install
1414
+
1403
1415
args = " " .join (sys .argv )
1404
1416
if not ("-n" in sys .argv or " -n=" in args or args == "-c" ):
1405
1417
# (Not multithreaded)
1406
- from seleniumbase .console_scripts import sb_install
1407
-
1408
1418
sys_args = sys .argv # Save a copy of current sys args
1409
1419
print ("\n Warning: geckodriver not found. Getting it now:" )
1410
1420
try :
1411
1421
sb_install .main (override = "geckodriver" )
1412
1422
except Exception as e :
1413
1423
print ("\n Warning: Could not install geckodriver: %s" % e )
1414
1424
sys .argv = sys_args # Put back the original sys args
1425
+ else :
1426
+ import fasteners
1427
+
1428
+ geckodriver_fixing_lock = fasteners .InterProcessLock (
1429
+ constants .MultiBrowser .DRIVER_FIXING_LOCK
1430
+ )
1431
+ with geckodriver_fixing_lock :
1432
+ if not is_geckodriver_on_path ():
1433
+ sys_args = sys .argv # Save a copy of sys args
1434
+ print (
1435
+ "\n Warning: geckodriver not found. "
1436
+ "Getting it now:"
1437
+ )
1438
+ sb_install .main (override = "geckodriver" )
1439
+ sys .argv = sys_args # Put back original sys args
1415
1440
warnings .simplefilter ("ignore" , category = DeprecationWarning )
1416
1441
if "linux" in PLATFORM :
1417
1442
from selenium .webdriver .common .desired_capabilities import (
@@ -1489,11 +1514,11 @@ def get_local_driver(
1489
1514
"\n Warning: Could not make IEDriver executable: %s" % e
1490
1515
)
1491
1516
elif not is_iedriver_on_path ():
1517
+ from seleniumbase .console_scripts import sb_install
1518
+
1492
1519
args = " " .join (sys .argv )
1493
1520
if not ("-n" in sys .argv or " -n=" in args or args == "-c" ):
1494
1521
# (Not multithreaded)
1495
- from seleniumbase .console_scripts import sb_install
1496
-
1497
1522
sys_args = sys .argv # Save a copy of current sys args
1498
1523
print ("\n Warning: IEDriver not found. Getting it now:" )
1499
1524
sb_install .main (override = "iedriver" )
@@ -1507,11 +1532,11 @@ def get_local_driver(
1507
1532
% e
1508
1533
)
1509
1534
elif not is_headless_iedriver_on_path ():
1535
+ from seleniumbase .console_scripts import sb_install
1536
+
1510
1537
args = " " .join (sys .argv )
1511
1538
if not ("-n" in sys .argv or " -n=" in args or args == "-c" ):
1512
1539
# (Not multithreaded)
1513
- from seleniumbase .console_scripts import sb_install
1514
-
1515
1540
sys_args = sys .argv # Save a copy of current sys args
1516
1541
print ("\n Warning: HeadlessIEDriver not found. Getting it now:" )
1517
1542
sb_install .main (override = "iedriver" )
@@ -1553,15 +1578,30 @@ def get_local_driver(
1553
1578
" executable: %s" % e
1554
1579
)
1555
1580
elif not is_edgedriver_on_path ():
1581
+ from seleniumbase .console_scripts import sb_install
1582
+
1556
1583
args = " " .join (sys .argv )
1557
1584
if not ("-n" in sys .argv or " -n=" in args or args == "-c" ):
1558
1585
# (Not multithreaded)
1559
- from seleniumbase .console_scripts import sb_install
1560
-
1561
1586
sys_args = sys .argv # Save a copy of current sys args
1562
1587
print ("\n Warning: msedgedriver not found. Getting it now:" )
1563
1588
sb_install .main (override = "edgedriver" )
1564
1589
sys .argv = sys_args # Put back the original sys args
1590
+ else :
1591
+ import fasteners
1592
+
1593
+ edgedriver_fixing_lock = fasteners .InterProcessLock (
1594
+ constants .MultiBrowser .DRIVER_FIXING_LOCK
1595
+ )
1596
+ with edgedriver_fixing_lock :
1597
+ if not is_edgedriver_on_path ():
1598
+ sys_args = sys .argv # Save a copy of sys args
1599
+ print (
1600
+ "\n Warning: msedgedriver not found. "
1601
+ "Getting it now:"
1602
+ )
1603
+ sb_install .main (override = "edgedriver" )
1604
+ sys .argv = sys_args # Put back original sys args
1565
1605
1566
1606
# For Microsoft Edge (Chromium) version 80 or higher
1567
1607
if selenium4 :
@@ -1732,16 +1772,16 @@ def get_local_driver(
1732
1772
import fasteners
1733
1773
1734
1774
edgedriver_fixing_lock = fasteners .InterProcessLock (
1735
- constants .MultiBrowser .CHROMEDRIVER_FIXING_LOCK
1775
+ constants .MultiBrowser .DRIVER_FIXING_LOCK
1736
1776
)
1737
1777
with edgedriver_fixing_lock :
1738
- if not _was_chromedriver_repaired (): # Works for Edge
1778
+ if not _was_driver_repaired ():
1739
1779
_repair_edgedriver (edge_version )
1740
- _mark_chromedriver_repaired () # Works for Edge
1780
+ _mark_driver_repaired ()
1741
1781
else :
1742
- if not _was_chromedriver_repaired (): # Works for Edge
1782
+ if not _was_driver_repaired ():
1743
1783
_repair_edgedriver (edge_version )
1744
- _mark_chromedriver_repaired () # Works for Edge
1784
+ _mark_driver_repaired ()
1745
1785
service = EdgeService (
1746
1786
executable_path = LOCAL_EDGEDRIVER , log_path = os .path .devnull
1747
1787
)
@@ -1779,16 +1819,16 @@ def get_local_driver(
1779
1819
import fasteners
1780
1820
1781
1821
edgedriver_fixing_lock = fasteners .InterProcessLock (
1782
- constants .MultiBrowser .CHROMEDRIVER_FIXING_LOCK
1822
+ constants .MultiBrowser .DRIVER_FIXING_LOCK
1783
1823
)
1784
1824
with edgedriver_fixing_lock :
1785
- if not _was_chromedriver_repaired (): # Works for Edge
1825
+ if not _was_driver_repaired ():
1786
1826
_repair_edgedriver (edge_version )
1787
- _mark_chromedriver_repaired () # Works for Edge
1827
+ _mark_driver_repaired ()
1788
1828
else :
1789
- if not _was_chromedriver_repaired (): # Works for Edge
1829
+ if not _was_driver_repaired ():
1790
1830
_repair_edgedriver (edge_version )
1791
- _mark_chromedriver_repaired () # Works for Edge
1831
+ _mark_driver_repaired ()
1792
1832
driver = Edge (
1793
1833
executable_path = LOCAL_EDGEDRIVER ,
1794
1834
service_log_path = os .path .devnull ,
@@ -1912,21 +1952,20 @@ def get_local_driver(
1912
1952
" executable: %s" % e
1913
1953
)
1914
1954
elif not is_chromedriver_on_path ():
1955
+ from seleniumbase .console_scripts import sb_install
1956
+
1915
1957
args = " " .join (sys .argv )
1916
1958
if not ("-n" in sys .argv or " -n=" in args or args == "-c" ):
1917
1959
# (Not multithreaded)
1918
- from seleniumbase .console_scripts import sb_install
1919
-
1920
1960
sys_args = sys .argv # Save a copy of current sys args
1921
1961
print ("\n Warning: chromedriver not found. Getting it now:" )
1922
- sb_install .main (override = "chromedriver" )
1962
+ sb_install .main (override = "chromedriver latest " )
1923
1963
sys .argv = sys_args # Put back the original sys args
1924
1964
else :
1925
1965
import fasteners
1926
- from seleniumbase .console_scripts import sb_install
1927
1966
1928
1967
chromedriver_fixing_lock = fasteners .InterProcessLock (
1929
- constants .MultiBrowser .CHROMEDRIVER_FIXING_LOCK
1968
+ constants .MultiBrowser .DRIVER_FIXING_LOCK
1930
1969
)
1931
1970
with chromedriver_fixing_lock :
1932
1971
if not is_chromedriver_on_path ():
@@ -1935,7 +1974,7 @@ def get_local_driver(
1935
1974
"\n Warning: chromedriver not found. "
1936
1975
"Getting it now:"
1937
1976
)
1938
- sb_install .main (override = "chromedriver" )
1977
+ sb_install .main (override = "chromedriver latest " )
1939
1978
sys .argv = sys_args # Put back original sys args
1940
1979
if not headless or "linux" not in PLATFORM :
1941
1980
try :
@@ -1976,6 +2015,16 @@ def get_local_driver(
1976
2015
raise Exception (e .msg ) # Not an obvious fix. Raise.
1977
2016
else :
1978
2017
pass # Try upgrading ChromeDriver to match Chrome.
2018
+ mcv = None # Major Chrome Version
2019
+ if "Current browser version is " in e .msg :
2020
+ line = e .msg .split ("Current browser version is " )[1 ]
2021
+ browser_version = line .split (" " )[0 ]
2022
+ major_chrome_version = browser_version .split ("." )[0 ]
2023
+ if (
2024
+ major_chrome_version .isnumeric ()
2025
+ and int (major_chrome_version ) >= 86
2026
+ ):
2027
+ mcv = major_chrome_version
1979
2028
headless = True
1980
2029
headless_options = _set_chrome_options (
1981
2030
browser_name ,
@@ -2018,20 +2067,20 @@ def get_local_driver(
2018
2067
import fasteners
2019
2068
2020
2069
chromedriver_fixing_lock = fasteners .InterProcessLock (
2021
- constants .MultiBrowser .CHROMEDRIVER_FIXING_LOCK
2070
+ constants .MultiBrowser .DRIVER_FIXING_LOCK
2022
2071
)
2023
2072
with chromedriver_fixing_lock :
2024
- if not _was_chromedriver_repaired ():
2073
+ if not _was_driver_repaired ():
2025
2074
_repair_chromedriver (
2026
- chrome_options , headless_options
2075
+ chrome_options , headless_options , mcv
2027
2076
)
2028
- _mark_chromedriver_repaired ()
2077
+ _mark_driver_repaired ()
2029
2078
else :
2030
- if not _was_chromedriver_repaired ():
2079
+ if not _was_driver_repaired ():
2031
2080
_repair_chromedriver (
2032
- chrome_options , headless_options
2081
+ chrome_options , headless_options , mcv
2033
2082
)
2034
- _mark_chromedriver_repaired ()
2083
+ _mark_driver_repaired ()
2035
2084
if os .path .exists (LOCAL_CHROMEDRIVER ):
2036
2085
if selenium4 :
2037
2086
service = ChromeService (
@@ -2058,32 +2107,42 @@ def get_local_driver(
2058
2107
auto_upgrade_chromedriver = True
2059
2108
elif "Chrome version must be between" in e .msg :
2060
2109
auto_upgrade_chromedriver = True
2110
+ mcv = None # Major Chrome Version
2111
+ if "Current browser version is " in e .msg :
2112
+ line = e .msg .split ("Current browser version is " )[1 ]
2113
+ browser_version = line .split (" " )[0 ]
2114
+ major_chrome_version = browser_version .split ("." )[0 ]
2115
+ if (
2116
+ major_chrome_version .isnumeric ()
2117
+ and int (major_chrome_version ) >= 86
2118
+ ):
2119
+ mcv = major_chrome_version
2061
2120
if auto_upgrade_chromedriver :
2062
2121
args = " " .join (sys .argv )
2063
2122
if "-n" in sys .argv or " -n=" in args or args == "-c" :
2064
2123
import fasteners
2065
2124
2066
2125
chromedr_fixing_lock = fasteners .InterProcessLock (
2067
- constants .MultiBrowser .CHROMEDRIVER_FIXING_LOCK
2126
+ constants .MultiBrowser .DRIVER_FIXING_LOCK
2068
2127
)
2069
2128
with chromedr_fixing_lock :
2070
- if not _was_chromedriver_repaired ():
2129
+ if not _was_driver_repaired ():
2071
2130
try :
2072
2131
_repair_chromedriver (
2073
- chrome_options , chrome_options
2132
+ chrome_options , chrome_options , mcv
2074
2133
)
2075
- _mark_chromedriver_repaired ()
2134
+ _mark_driver_repaired ()
2076
2135
except Exception :
2077
2136
pass
2078
2137
else :
2079
- if not _was_chromedriver_repaired ():
2138
+ if not _was_driver_repaired ():
2080
2139
try :
2081
2140
_repair_chromedriver (
2082
- chrome_options , chrome_options
2141
+ chrome_options , chrome_options , mcv
2083
2142
)
2084
2143
except Exception :
2085
2144
pass
2086
- _mark_chromedriver_repaired ()
2145
+ _mark_driver_repaired ()
2087
2146
try :
2088
2147
return webdriver .Chrome (options = chrome_options )
2089
2148
except Exception :
0 commit comments