Skip to content

Commit c483c59

Browse files
committed
Prevent webdrivers from creating unnecessary log files
1 parent 69ae9f3 commit c483c59

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,7 +1430,10 @@ def get_local_driver(
14301430
else:
14311431
if os.path.exists(LOCAL_GECKODRIVER):
14321432
if selenium4:
1433-
service = FirefoxService(executable_path=LOCAL_GECKODRIVER)
1433+
service = FirefoxService(
1434+
executable_path=LOCAL_GECKODRIVER,
1435+
log_path=os.path.devnull,
1436+
)
14341437
try:
14351438
return webdriver.Firefox(
14361439
service=service,
@@ -1449,10 +1452,20 @@ def get_local_driver(
14491452
else:
14501453
return webdriver.Firefox(
14511454
executable_path=LOCAL_GECKODRIVER,
1455+
service_log_path=os.path.devnull,
14521456
options=firefox_options,
14531457
)
14541458
else:
1455-
return webdriver.Firefox(options=firefox_options)
1459+
if selenium4:
1460+
service = FirefoxService(log_path=os.path.devnull)
1461+
return webdriver.Firefox(
1462+
service=service, options=firefox_options
1463+
)
1464+
else:
1465+
return webdriver.Firefox(
1466+
service_log_path=os.path.devnull,
1467+
options=firefox_options,
1468+
)
14561469
elif browser_name == constants.Browser.INTERNET_EXPLORER:
14571470
if not IS_WINDOWS:
14581471
raise Exception(
@@ -1692,7 +1705,9 @@ def get_local_driver(
16921705
edge_options.add_argument(chromium_arg_item)
16931706
if selenium4:
16941707
try:
1695-
service = EdgeService(executable_path=LOCAL_EDGEDRIVER)
1708+
service = EdgeService(
1709+
executable_path=LOCAL_EDGEDRIVER, log_path=os.path.devnull
1710+
)
16961711
driver = Edge(service=service, options=edge_options)
16971712
except Exception as e:
16981713
auto_upgrade_edgedriver = False
@@ -1727,7 +1742,9 @@ def get_local_driver(
17271742
if not _was_chromedriver_repaired(): # Works for Edge
17281743
_repair_edgedriver(edge_version)
17291744
_mark_chromedriver_repaired() # Works for Edge
1730-
service = EdgeService(executable_path=LOCAL_EDGEDRIVER)
1745+
service = EdgeService(
1746+
executable_path=LOCAL_EDGEDRIVER, log_path=os.path.devnull
1747+
)
17311748
driver = Edge(service=service, options=edge_options)
17321749
return driver
17331750
else:
@@ -1736,6 +1753,7 @@ def get_local_driver(
17361753
try:
17371754
driver = Edge(
17381755
executable_path=LOCAL_EDGEDRIVER,
1756+
service_log_path=os.path.devnull,
17391757
capabilities=capabilities,
17401758
)
17411759
except Exception as e:
@@ -1773,6 +1791,7 @@ def get_local_driver(
17731791
_mark_chromedriver_repaired() # Works for Edge
17741792
driver = Edge(
17751793
executable_path=LOCAL_EDGEDRIVER,
1794+
service_log_path=os.path.devnull,
17761795
capabilities=capabilities,
17771796
)
17781797
return driver
@@ -1923,7 +1942,8 @@ def get_local_driver(
19231942
if os.path.exists(LOCAL_CHROMEDRIVER):
19241943
if selenium4:
19251944
service = ChromeService(
1926-
executable_path=LOCAL_CHROMEDRIVER
1945+
executable_path=LOCAL_CHROMEDRIVER,
1946+
log_path=os.path.devnull,
19271947
)
19281948
driver = webdriver.Chrome(
19291949
service=service,
@@ -1932,10 +1952,20 @@ def get_local_driver(
19321952
else:
19331953
driver = webdriver.Chrome(
19341954
executable_path=LOCAL_CHROMEDRIVER,
1955+
service_log_path=os.path.devnull,
19351956
options=chrome_options,
19361957
)
19371958
else:
1938-
driver = webdriver.Chrome(options=chrome_options)
1959+
if selenium4:
1960+
service = ChromeService(log_path=os.path.devnull)
1961+
driver = webdriver.Chrome(
1962+
service=service, options=chrome_options
1963+
)
1964+
else:
1965+
driver = webdriver.Chrome(
1966+
options=chrome_options,
1967+
service_log_path=os.path.devnull,
1968+
)
19391969
except Exception as e:
19401970
auto_upgrade_chromedriver = False
19411971
if "This version of ChromeDriver only supports" in e.msg:

0 commit comments

Comments
 (0)