5
5
import urllib3
6
6
import warnings
7
7
from selenium import webdriver
8
+ from selenium .webdriver .chrome .service import Service as Chrome_Service
9
+ from selenium .webdriver .edge .service import Service as Edge_Service
10
+ from selenium .webdriver .firefox .service import Service as Firefox_Service
8
11
from seleniumbase .config import settings
9
12
from seleniumbase .core import download_helper
10
13
from seleniumbase .core import proxy_helper
13
16
from seleniumbase import extensions # browser extensions storage folder
14
17
15
18
urllib3 .disable_warnings ()
19
+ selenium4 = False
20
+ if sys .version_info [0 ] == 3 and sys .version_info [1 ] >= 7 :
21
+ selenium4 = True
16
22
DRIVER_DIR = os .path .dirname (os .path .realpath (drivers .__file__ ))
17
23
# Make sure that the SeleniumBase DRIVER_DIR is at the top of the System PATH
18
24
# (Changes to the System PATH with os.environ only last during the test run)
@@ -116,7 +122,18 @@ def _repair_chromedriver(chrome_options, headless_options):
116
122
"sbase install chromedriver 2.44" , shell = True
117
123
)
118
124
try :
119
- driver = webdriver .Chrome (options = headless_options )
125
+ if selenium4 :
126
+ service = Chrome_Service (
127
+ executable_path = LOCAL_CHROMEDRIVER )
128
+ driver = webdriver .Chrome (
129
+ service = service ,
130
+ options = headless_options ,
131
+ )
132
+ else :
133
+ driver = webdriver .Chrome (
134
+ executable_path = LOCAL_CHROMEDRIVER ,
135
+ options = headless_options ,
136
+ )
120
137
except Exception :
121
138
subprocess .check_call (
122
139
"sbase install chromedriver latest-1" , shell = True
@@ -1132,11 +1149,18 @@ def get_local_driver(
1132
1149
)
1133
1150
else :
1134
1151
if os .path .exists (LOCAL_GECKODRIVER ):
1135
- warnings .simplefilter ("ignore" , category = DeprecationWarning )
1136
- return webdriver .Firefox (
1137
- executable_path = LOCAL_GECKODRIVER ,
1138
- options = firefox_options ,
1139
- )
1152
+ if selenium4 :
1153
+ service = Firefox_Service (
1154
+ executable_path = LOCAL_GECKODRIVER )
1155
+ return webdriver .Firefox (
1156
+ service = service ,
1157
+ options = firefox_options ,
1158
+ )
1159
+ else :
1160
+ return webdriver .Firefox (
1161
+ executable_path = LOCAL_GECKODRIVER ,
1162
+ options = firefox_options ,
1163
+ )
1140
1164
else :
1141
1165
return webdriver .Firefox (options = firefox_options )
1142
1166
elif browser_name == constants .Browser .INTERNET_EXPLORER :
@@ -1269,10 +1293,6 @@ def get_local_driver(
1269
1293
sb_install .main (override = "edgedriver" )
1270
1294
sys .argv = sys_args # Put back the original sys args
1271
1295
1272
- selenium4 = False
1273
- if sys .version_info [0 ] == 3 and sys .version_info [1 ] >= 7 :
1274
- selenium4 = True
1275
-
1276
1296
# For Microsoft Edge (Chromium) version 80 or higher
1277
1297
if selenium4 :
1278
1298
Edge = webdriver .edge .webdriver .WebDriver
@@ -1410,12 +1430,9 @@ def get_local_driver(
1410
1430
if len (chromium_arg_item ) >= 3 :
1411
1431
edge_options .add_argument (chromium_arg_item )
1412
1432
if selenium4 :
1413
- warnings .simplefilter ("ignore" , category = DeprecationWarning )
1414
1433
try :
1415
- driver = Edge (
1416
- executable_path = LOCAL_EDGEDRIVER ,
1417
- options = edge_options ,
1418
- )
1434
+ service = Edge_Service (executable_path = LOCAL_EDGEDRIVER )
1435
+ driver = Edge (service = service , options = edge_options )
1419
1436
except Exception as e :
1420
1437
auto_upgrade_edgedriver = False
1421
1438
if "This version of MSEdgeDriver only supports" in e .msg :
@@ -1442,10 +1459,8 @@ def get_local_driver(
1442
1459
if not _was_chromedriver_repaired (): # Works for Edge
1443
1460
_repair_edgedriver (edge_version )
1444
1461
_mark_chromedriver_repaired () # Works for Edge
1445
- driver = Edge (
1446
- executable_path = LOCAL_EDGEDRIVER ,
1447
- options = edge_options ,
1448
- )
1462
+ service = Edge_Service (executable_path = LOCAL_EDGEDRIVER )
1463
+ driver = Edge (service = service , options = edge_options )
1449
1464
return driver
1450
1465
else :
1451
1466
capabilities = edge_options .to_capabilities ()
@@ -1538,6 +1553,7 @@ def get_local_driver(
1538
1553
device_pixel_ratio ,
1539
1554
)
1540
1555
opera_options .headless = False # No support for headless Opera
1556
+ warnings .simplefilter ("ignore" , category = DeprecationWarning )
1541
1557
return webdriver .Opera (options = opera_options )
1542
1558
except Exception :
1543
1559
return webdriver .Opera ()
@@ -1619,12 +1635,18 @@ def get_local_driver(
1619
1635
if not headless or "linux" not in PLATFORM :
1620
1636
try :
1621
1637
if os .path .exists (LOCAL_CHROMEDRIVER ):
1622
- warnings .simplefilter (
1623
- "ignore" , category = DeprecationWarning )
1624
- driver = webdriver .Chrome (
1625
- executable_path = LOCAL_CHROMEDRIVER ,
1626
- options = chrome_options ,
1627
- )
1638
+ if selenium4 :
1639
+ service = Chrome_Service (
1640
+ executable_path = LOCAL_CHROMEDRIVER )
1641
+ driver = webdriver .Chrome (
1642
+ service = service ,
1643
+ options = chrome_options ,
1644
+ )
1645
+ else :
1646
+ driver = webdriver .Chrome (
1647
+ executable_path = LOCAL_CHROMEDRIVER ,
1648
+ options = chrome_options ,
1649
+ )
1628
1650
else :
1629
1651
driver = webdriver .Chrome (options = chrome_options )
1630
1652
except Exception as e :
@@ -1692,12 +1714,18 @@ def get_local_driver(
1692
1714
)
1693
1715
_mark_chromedriver_repaired ()
1694
1716
if os .path .exists (LOCAL_CHROMEDRIVER ):
1695
- warnings .simplefilter (
1696
- "ignore" , category = DeprecationWarning )
1697
- driver = webdriver .Chrome (
1698
- executable_path = LOCAL_CHROMEDRIVER ,
1699
- options = chrome_options ,
1700
- )
1717
+ if selenium4 :
1718
+ service = Chrome_Service (
1719
+ executable_path = LOCAL_CHROMEDRIVER )
1720
+ driver = webdriver .Chrome (
1721
+ service = service ,
1722
+ options = chrome_options ,
1723
+ )
1724
+ else :
1725
+ driver = webdriver .Chrome (
1726
+ executable_path = LOCAL_CHROMEDRIVER ,
1727
+ options = chrome_options ,
1728
+ )
1701
1729
else :
1702
1730
driver = webdriver .Chrome (options = chrome_options )
1703
1731
return driver
0 commit comments