2
2
import logging
3
3
import os
4
4
import re
5
- import sys
5
+ import shutil
6
6
import subprocess
7
+ import sys
7
8
import time
8
9
import urllib3
9
10
import warnings
53
54
LOCAL_IEDRIVER = None
54
55
LOCAL_HEADLESS_IEDRIVER = None
55
56
LOCAL_OPERADRIVER = None
57
+ LOCAL_UC_DRIVER = None
56
58
if "darwin" in PLATFORM or "linux" in PLATFORM :
57
59
LOCAL_CHROMEDRIVER = DRIVER_DIR + "/chromedriver"
58
60
LOCAL_GECKODRIVER = DRIVER_DIR + "/geckodriver"
59
61
LOCAL_EDGEDRIVER = DRIVER_DIR + "/msedgedriver"
60
62
LOCAL_OPERADRIVER = DRIVER_DIR + "/operadriver"
63
+ LOCAL_UC_DRIVER = DRIVER_DIR + "/uc_driver"
61
64
elif "win32" in PLATFORM or "win64" in PLATFORM or "x64" in PLATFORM :
62
65
IS_WINDOWS = True
63
66
LOCAL_EDGEDRIVER = DRIVER_DIR + "/msedgedriver.exe"
66
69
LOCAL_CHROMEDRIVER = DRIVER_DIR + "/chromedriver.exe"
67
70
LOCAL_GECKODRIVER = DRIVER_DIR + "/geckodriver.exe"
68
71
LOCAL_OPERADRIVER = DRIVER_DIR + "/operadriver.exe"
72
+ LOCAL_UC_DRIVER = DRIVER_DIR + "/uc_driver.exe"
69
73
else :
70
74
# Cannot determine system
71
75
pass # SeleniumBase will use web drivers from the System PATH by default
@@ -356,24 +360,24 @@ def _set_chrome_options(
356
360
chrome_options = undetected .ChromeOptions ()
357
361
elif browser_name == constants .Browser .OPERA :
358
362
chrome_options = webdriver .opera .options .Options ()
359
- prefs = {
360
- "download.default_directory" : downloads_path ,
361
- "local_discovery.notifications_enabled" : False ,
362
- "credentials_enable_service" : False ,
363
- "download.prompt_for_download" : False ,
364
- "download.directory_upgrade" : True ,
365
- "safebrowsing.enabled" : False ,
366
- "safebrowsing.disable_download_protection" : True ,
367
- "default_content_setting_values.notifications" : 0 ,
368
- "default_content_settings.popups" : 0 ,
369
- "managed_default_content_settings.popups" : 0 ,
370
- "content_settings.exceptions.automatic_downloads.*.setting" : 1 ,
371
- "profile.password_manager_enabled" : False ,
372
- "profile.default_content_setting_values.notifications" : 2 ,
373
- "profile.default_content_settings.popups" : 0 ,
374
- "profile.managed_default_content_settings .popups" : 0 ,
375
- "profile.default_content_setting_values.automatic_downloads" : 1 ,
376
- }
363
+
364
+ prefs = {}
365
+ prefs [ "download.default_directory" ] = downloads_path
366
+ prefs [ "local_discovery.notifications_enabled" ] = False
367
+ prefs [ "credentials_enable_service" ] = False
368
+ prefs [ "download.prompt_for_download" ] = False
369
+ prefs [ "download.directory_upgrade" ] = True
370
+ prefs [ "safebrowsing.enabled" ] = False
371
+ prefs [ "default_content_setting_values.notifications" ] = 0
372
+ prefs [ "content_settings.exceptions.automatic_downloads.*.setting" ] = 1
373
+ prefs [ "safebrowsing.disable_download_protection" ] = True
374
+ prefs [ "default_content_settings.popups" ] = 0
375
+ prefs [ "managed_default_content_settings.popups" ] = 0
376
+ prefs [ "profile.password_manager_enabled" ] = False
377
+ prefs [ "profile.default_content_setting_values.notifications" ] = 2
378
+ prefs [ "profile.default_content_settings .popups" ] = 0
379
+ prefs [ "profile.managed_default_content_settings.popups" ] = 0
380
+ prefs [ "profile.default_content_setting_values.automatic_downloads" ] = 1
377
381
if locale_code :
378
382
prefs ["intl.accept_languages" ] = locale_code
379
383
if block_images :
@@ -477,31 +481,6 @@ def _set_chrome_options(
477
481
# load-extension input can be a comma-separated list
478
482
abs_path = os .path .abspath (extension_dir )
479
483
chrome_options = add_chrome_ext_dir (chrome_options , abs_path )
480
- chrome_options .add_argument ("--test-type" )
481
- chrome_options .add_argument ("--log-level=3" )
482
- chrome_options .add_argument ("--no-first-run" )
483
- if devtools and not headless :
484
- chrome_options .add_argument ("--auto-open-devtools-for-tabs" )
485
- chrome_options .add_argument ("--allow-file-access-from-files" )
486
- chrome_options .add_argument ("--allow-insecure-localhost" )
487
- chrome_options .add_argument ("--allow-running-insecure-content" )
488
- if user_agent :
489
- chrome_options .add_argument ("--user-agent=%s" % user_agent )
490
- chrome_options .add_argument ("--disable-infobars" )
491
- chrome_options .add_argument ("--disable-notifications" )
492
- chrome_options .add_argument ("--disable-save-password-bubble" )
493
- chrome_options .add_argument ("--disable-single-click-autofill" )
494
- chrome_options .add_argument (
495
- "--disable-autofill-keyboard-accessory-view[8]"
496
- )
497
- chrome_options .add_argument ("--disable-browser-side-navigation" )
498
- chrome_options .add_argument ("--disable-translate" )
499
- chrome_options .add_argument ("--homepage=about:blank" )
500
- chrome_options .add_argument ("--dns-prefetch-disable" )
501
- chrome_options .add_argument ("--dom-automation" )
502
- chrome_options .add_argument ("--disable-hang-monitor" )
503
- chrome_options .add_argument ("--disable-prompt-on-repost" )
504
- chrome_options .add_argument ("--disable-3d-apis" )
505
484
if (
506
485
selenium4_or_newer
507
486
and page_load_strategy
@@ -619,6 +598,33 @@ def _set_chrome_options(
619
598
chromium_arg_item = "--" + chromium_arg_item
620
599
if len (chromium_arg_item ) >= 3 :
621
600
chrome_options .add_argument (chromium_arg_item )
601
+ if devtools and not headless :
602
+ chrome_options .add_argument ("--auto-open-devtools-for-tabs" )
603
+ if user_agent :
604
+ chrome_options .add_argument ("--user-agent=%s" % user_agent )
605
+ chrome_options .add_argument ("--disable-browser-side-navigation" )
606
+ chrome_options .add_argument ("--disable-save-password-bubble" )
607
+ chrome_options .add_argument ("--disable-single-click-autofill" )
608
+ chrome_options .add_argument ("--allow-file-access-from-files" )
609
+ chrome_options .add_argument ("--disable-prompt-on-repost" )
610
+ chrome_options .add_argument ("--dns-prefetch-disable" )
611
+ chrome_options .add_argument ("--disable-translate" )
612
+ chrome_options .add_argument ("--disable-3d-apis" )
613
+ if is_using_uc (undetectable , browser_name ):
614
+ return chrome_options
615
+ chrome_options .add_argument ("--test-type" )
616
+ chrome_options .add_argument ("--log-level=3" )
617
+ chrome_options .add_argument ("--no-first-run" )
618
+ chrome_options .add_argument ("--allow-insecure-localhost" )
619
+ chrome_options .add_argument ("--allow-running-insecure-content" )
620
+ chrome_options .add_argument ("--disable-infobars" )
621
+ chrome_options .add_argument ("--disable-notifications" )
622
+ chrome_options .add_argument (
623
+ "--disable-autofill-keyboard-accessory-view[8]"
624
+ )
625
+ chrome_options .add_argument ("--homepage=about:blank" )
626
+ chrome_options .add_argument ("--dom-automation" )
627
+ chrome_options .add_argument ("--disable-hang-monitor" )
622
628
return chrome_options
623
629
624
630
@@ -2340,6 +2346,45 @@ def get_local_driver(
2340
2346
override = "chromedriver %s" % use_version
2341
2347
)
2342
2348
sys .argv = sys_args # Put back original sys args
2349
+ if is_using_uc (undetectable , browser_name ):
2350
+ uc_lock = fasteners .InterProcessLock (
2351
+ constants .MultiBrowser .DRIVER_FIXING_LOCK
2352
+ )
2353
+ with uc_lock : # No UC multithreaded tests
2354
+ uc_driver_version = None
2355
+ if os .path .exists (LOCAL_UC_DRIVER ):
2356
+ try :
2357
+ output = subprocess .check_output (
2358
+ "%s --version" % LOCAL_UC_DRIVER , shell = True
2359
+ )
2360
+ if IS_WINDOWS :
2361
+ output = output .decode ("latin1" )
2362
+ else :
2363
+ output = output .decode ("utf-8" )
2364
+ output = output .split (" " )[1 ].split ("." )[0 ]
2365
+ if int (output ) >= 72 :
2366
+ uc_driver_version = output
2367
+ except Exception :
2368
+ pass
2369
+ if (
2370
+ uc_driver_version != use_version
2371
+ and use_version != "latest"
2372
+ ):
2373
+ if os .path .exists (LOCAL_CHROMEDRIVER ):
2374
+ shutil .copyfile (
2375
+ LOCAL_CHROMEDRIVER , LOCAL_UC_DRIVER
2376
+ )
2377
+ elif os .path .exists (path_chromedriver ):
2378
+ shutil .copyfile (
2379
+ path_chromedriver , LOCAL_UC_DRIVER
2380
+ )
2381
+ try :
2382
+ make_driver_executable_if_not (LOCAL_UC_DRIVER )
2383
+ except Exception as e :
2384
+ logging .debug (
2385
+ "\n Warning: Could not make uc_driver"
2386
+ " executable: %s" % e
2387
+ )
2343
2388
if (
2344
2389
not headless
2345
2390
or "linux" not in PLATFORM
@@ -2377,9 +2422,14 @@ def get_local_driver(
2377
2422
)
2378
2423
with uc_lock : # No UC multithreaded tests
2379
2424
try :
2425
+ uc_path = None
2426
+ if os .path .exists (LOCAL_UC_DRIVER ):
2427
+ uc_path = LOCAL_UC_DRIVER
2428
+ uc_path = os .path .realpath (uc_path )
2380
2429
driver = undetected .Chrome (
2381
2430
options = chrome_options ,
2382
- headless = False , # Xvfb needed
2431
+ driver_executable_path = uc_path ,
2432
+ headless = False , # Xvfb needed!
2383
2433
version_main = uc_chrome_version ,
2384
2434
)
2385
2435
except URLError as e :
@@ -2394,7 +2444,8 @@ def get_local_driver(
2394
2444
)
2395
2445
driver = undetected .Chrome (
2396
2446
options = chrome_options ,
2397
- headless = False , # Xvfb needed
2447
+ driver_executable_path = uc_path ,
2448
+ headless = False , # Xvfb needed!
2398
2449
version_main = uc_chrome_version ,
2399
2450
)
2400
2451
else :
0 commit comments