2
2
import logging
3
3
import os
4
4
import re
5
+ import requests
5
6
import subprocess
6
7
import sys
7
8
import time
@@ -138,8 +139,6 @@ def __init__(
138
139
options ._session = self
139
140
debug_host = "127.0.0.1"
140
141
debug_port = 9222
141
- import requests
142
-
143
142
special_port_free = False # If the port isn't free, don't use 9222
144
143
try :
145
144
res = requests .get ("http://127.0.0.1:9222" , timeout = 1 )
@@ -151,7 +150,6 @@ def __init__(
151
150
sys_argv = sys .argv
152
151
arg_join = " " .join (sys_argv )
153
152
from seleniumbase import config as sb_config
154
-
155
153
if (
156
154
(("-n" in sys .argv ) or (" -n=" in arg_join ) or ("-c" in sys .argv ))
157
155
or (hasattr (sb_config , "multi_proxy" ) and sb_config .multi_proxy )
@@ -197,7 +195,6 @@ def __init__(
197
195
keep_user_data_dir = True
198
196
else :
199
197
import tempfile
200
-
201
198
user_data_dir = os .path .normpath (tempfile .mkdtemp ())
202
199
keep_user_data_dir = False
203
200
arg = "--user-data-dir=%s" % user_data_dir
@@ -206,7 +203,6 @@ def __init__(
206
203
if not language :
207
204
try :
208
205
import locale
209
-
210
206
language = locale .getlocale ()[0 ].replace ("_" , "-" )
211
207
except Exception :
212
208
pass
@@ -241,7 +237,6 @@ def __init__(
241
237
options .handle_prefs (user_data_dir )
242
238
try :
243
239
import json
244
-
245
240
with open (
246
241
os .path .join (
247
242
os .path .abspath (user_data_dir ),
@@ -286,19 +281,22 @@ def __init__(
286
281
)
287
282
self .browser_pid = browser .pid
288
283
service_ = None
284
+ log_output = subprocess .PIPE
285
+ if sys .version_info < (3 , 8 ):
286
+ log_output = os .devnull
289
287
if patch_driver :
290
288
service_ = selenium .webdriver .chrome .service .Service (
291
289
executable_path = self .patcher .executable_path ,
292
290
service_args = ["--disable-build-check" ],
293
291
port = port ,
294
- log_output = os . devnull ,
292
+ log_output = log_output ,
295
293
)
296
294
else :
297
295
service_ = selenium .webdriver .chrome .service .Service (
298
296
executable_path = driver_executable_path ,
299
297
service_args = ["--disable-build-check" ],
300
298
port = port ,
301
- log_output = os . devnull ,
299
+ log_output = log_output ,
302
300
)
303
301
if hasattr (service_ , "creationflags" ):
304
302
setattr (service_ , "creationflags" , creationflags )
@@ -321,7 +319,6 @@ def __getattribute__(self, item):
321
319
return super ().__getattribute__ (item )
322
320
else :
323
321
import inspect
324
-
325
322
original = super ().__getattribute__ (item )
326
323
if inspect .ismethod (original ) and not inspect .isclass (original ):
327
324
def newfunc (* args , ** kwargs ):
@@ -455,7 +452,6 @@ def quit(self):
455
452
and not self .keep_user_data_dir
456
453
):
457
454
import shutil
458
-
459
455
for _ in range (5 ):
460
456
try :
461
457
shutil .rmtree (self .user_data_dir , ignore_errors = False )
@@ -506,7 +502,6 @@ def __hash__(self):
506
502
507
503
def find_chrome_executable ():
508
504
from seleniumbase .core import detect_b_ver
509
-
510
505
binary_location = detect_b_ver .get_binary_location ("google-chrome" , True )
511
506
if os .path .exists (binary_location ) and os .access (binary_location , os .X_OK ):
512
507
return os .path .normpath (binary_location )
0 commit comments