seleniumbase 4.27.5__py3-none-any.whl → 4.28.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1251,9 +1251,17 @@ class BaseCase(unittest.TestCase):
1251
1251
  if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
1252
1252
  timeout = self.__get_new_timeout(timeout)
1253
1253
  selector, by = self.__recalculate_selector(selector, by)
1254
- element = self.wait_for_element_visible(
1254
+ element = self.wait_for_element_present(
1255
1255
  selector, by=by, timeout=timeout
1256
1256
  )
1257
+ if not element.is_displayed():
1258
+ css_selector = self.convert_to_css_selector(selector, by=by)
1259
+ css_selector = re.escape(css_selector) # Add "\\" to special chars
1260
+ css_selector = self.__escape_quotes_if_needed(css_selector)
1261
+ script = """document.querySelector('%s').focus();""" % css_selector
1262
+ self.execute_script(script)
1263
+ self.__demo_mode_pause_if_active()
1264
+ return
1257
1265
  self.scroll_to(selector, by=by, timeout=timeout)
1258
1266
  try:
1259
1267
  element.send_keys(Keys.NULL)
@@ -1828,7 +1836,7 @@ class BaseCase(unittest.TestCase):
1828
1836
  elif self.slow_mode:
1829
1837
  self.__slow_mode_pause_if_active()
1830
1838
 
1831
- def get_text(self, selector, by="css selector", timeout=None):
1839
+ def get_text(self, selector="html", by="css selector", timeout=None):
1832
1840
  self.__check_scope()
1833
1841
  if not timeout:
1834
1842
  timeout = settings.LARGE_TIMEOUT
@@ -2083,7 +2091,9 @@ class BaseCase(unittest.TestCase):
2083
2091
  return ""
2084
2092
  return property_value
2085
2093
 
2086
- def get_text_content(self, selector, by="css selector", timeout=None):
2094
+ def get_text_content(
2095
+ self, selector="html", by="css selector", timeout=None
2096
+ ):
2087
2097
  """Returns the text that appears in the HTML for an element.
2088
2098
  This is different from "self.get_text(selector, by="css selector")"
2089
2099
  because that only returns the visible text on a page for an element,
@@ -3401,7 +3411,7 @@ class BaseCase(unittest.TestCase):
3401
3411
  self.driver.maximize_window()
3402
3412
  self.__demo_mode_pause_if_active()
3403
3413
 
3404
- def switch_to_frame(self, frame, timeout=None):
3414
+ def switch_to_frame(self, frame="iframe", timeout=None):
3405
3415
  """Wait for an iframe to appear, and switch to it. This should be
3406
3416
  usable as a drop-in replacement for driver.switch_to.frame().
3407
3417
  The iframe identifier can be a selector, an index, an id, a name,
@@ -3728,15 +3738,11 @@ class BaseCase(unittest.TestCase):
3728
3738
  """Opens a new browser tab/window and switches to it by default."""
3729
3739
  self.wait_for_ready_state_complete()
3730
3740
  if switch_to:
3731
- if self.undetectable:
3732
- self.driver.execute_script("window.open('data:,');")
3741
+ try:
3742
+ self.driver.switch_to.new_window("tab")
3743
+ except Exception:
3744
+ self.driver.execute_script("window.open('');")
3733
3745
  self.switch_to_newest_window()
3734
- else:
3735
- try:
3736
- self.driver.switch_to.new_window("tab")
3737
- except Exception:
3738
- self.driver.execute_script("window.open('');")
3739
- self.switch_to_newest_window()
3740
3746
  else:
3741
3747
  self.driver.execute_script("window.open('');")
3742
3748
  time.sleep(0.01)
@@ -4166,6 +4172,14 @@ class BaseCase(unittest.TestCase):
4166
4172
  self.connect = new_driver.connect
4167
4173
  if hasattr(new_driver, "uc_click"):
4168
4174
  self.uc_click = new_driver.uc_click
4175
+ if hasattr(new_driver, "uc_gui_press_key"):
4176
+ self.uc_gui_press_key = new_driver.uc_gui_press_key
4177
+ if hasattr(new_driver, "uc_gui_press_keys"):
4178
+ self.uc_gui_press_keys = new_driver.uc_gui_press_keys
4179
+ if hasattr(new_driver, "uc_gui_write"):
4180
+ self.uc_gui_write = new_driver.uc_gui_write
4181
+ if hasattr(new_driver, "uc_gui_handle_cf"):
4182
+ self.uc_gui_handle_cf = new_driver.uc_gui_handle_cf
4169
4183
  if hasattr(new_driver, "uc_switch_to_frame"):
4170
4184
  self.uc_switch_to_frame = new_driver.uc_switch_to_frame
4171
4185
  return new_driver
@@ -6808,9 +6822,11 @@ class BaseCase(unittest.TestCase):
6808
6822
  try:
6809
6823
  import cryptography
6810
6824
  if cryptography.__version__ != "39.0.2":
6825
+ del cryptography # To get newer ver
6811
6826
  shared_utils.pip_install(
6812
6827
  "cryptography", version="39.0.2"
6813
6828
  )
6829
+ import cryptography
6814
6830
  except Exception:
6815
6831
  shared_utils.pip_install(
6816
6832
  "cryptography", version="39.0.2"
@@ -13681,23 +13697,95 @@ class BaseCase(unittest.TestCase):
13681
13697
  pass # JQuery probably couldn't load. Skip highlighting.
13682
13698
  time.sleep(0.065)
13683
13699
 
13700
+ def __activate_standard_virtual_display(self):
13701
+ from sbvirtualdisplay import Display
13702
+ width = settings.HEADLESS_START_WIDTH
13703
+ height = settings.HEADLESS_START_HEIGHT
13704
+ try:
13705
+ self._xvfb_display = Display(
13706
+ visible=0, size=(width, height)
13707
+ )
13708
+ self._xvfb_display.start()
13709
+ sb_config._virtual_display = self._xvfb_display
13710
+ self.headless_active = True
13711
+ sb_config.headless_active = True
13712
+ except Exception:
13713
+ pass
13714
+
13684
13715
  def __activate_virtual_display_as_needed(self):
13685
13716
  """Should be needed only on Linux.
13686
13717
  The "--xvfb" arg is still useful, as it prevents headless mode,
13687
13718
  which is the default mode on Linux unless using another arg."""
13688
13719
  if "linux" in sys.platform and (not self.headed or self.xvfb):
13689
- width = settings.HEADLESS_START_WIDTH
13690
- height = settings.HEADLESS_START_HEIGHT
13691
- try:
13692
- from sbvirtualdisplay import Display
13693
-
13694
- self._xvfb_display = Display(visible=0, size=(width, height))
13695
- self._xvfb_display.start()
13696
- sb_config._virtual_display = self._xvfb_display
13697
- self.headless_active = True
13698
- sb_config.headless_active = True
13699
- except Exception:
13700
- pass
13720
+ from sbvirtualdisplay import Display
13721
+ if self.undetectable and not (self.headless or self.headless2):
13722
+ import Xlib.display
13723
+ try:
13724
+ self._xvfb_display = Display(
13725
+ visible=True,
13726
+ size=(1366, 768),
13727
+ backend="xvfb",
13728
+ use_xauth=True,
13729
+ )
13730
+ self._xvfb_display.start()
13731
+ if "DISPLAY" not in os.environ.keys():
13732
+ print("\nX11 display failed! Will use regular xvfb!")
13733
+ self.__activate_standard_virtual_display()
13734
+ except Exception as e:
13735
+ if hasattr(e, "msg"):
13736
+ print("\n" + str(e.msg))
13737
+ else:
13738
+ print(e)
13739
+ print("\nX11 display failed! Will use regular xvfb!")
13740
+ self.__activate_standard_virtual_display()
13741
+ return
13742
+ pip_find_lock = fasteners.InterProcessLock(
13743
+ constants.PipInstall.FINDLOCK
13744
+ )
13745
+ with pip_find_lock: # Prevent issues with multiple processes
13746
+ pyautogui_is_installed = False
13747
+ try:
13748
+ import pyautogui
13749
+ try:
13750
+ use_pyautogui_ver = constants.PyAutoGUI.VER
13751
+ if pyautogui.__version__ != use_pyautogui_ver:
13752
+ del pyautogui # To get newer ver
13753
+ shared_utils.pip_install(
13754
+ "pyautogui", version=use_pyautogui_ver
13755
+ )
13756
+ import pyautogui
13757
+ except Exception:
13758
+ pass
13759
+ pyautogui_is_installed = True
13760
+ except Exception:
13761
+ message = (
13762
+ "PyAutoGUI is required for UC Mode on Linux! "
13763
+ "Installing now..."
13764
+ )
13765
+ print("\n" + message)
13766
+ shared_utils.pip_install(
13767
+ "pyautogui", version=constants.PyAutoGUI.VER
13768
+ )
13769
+ import pyautogui
13770
+ pyautogui_is_installed = True
13771
+ if (
13772
+ pyautogui_is_installed
13773
+ and hasattr(pyautogui, "_pyautogui_x11")
13774
+ ):
13775
+ try:
13776
+ pyautogui._pyautogui_x11._display = (
13777
+ Xlib.display.Display(os.environ['DISPLAY'])
13778
+ )
13779
+ sb_config._pyautogui_x11_display = (
13780
+ pyautogui._pyautogui_x11._display
13781
+ )
13782
+ except Exception as e:
13783
+ if hasattr(e, "msg"):
13784
+ print("\n" + str(e.msg))
13785
+ else:
13786
+ print(e)
13787
+ else:
13788
+ self.__activate_standard_virtual_display()
13701
13789
 
13702
13790
  def __ad_block_as_needed(self):
13703
13791
  """This is an internal method for handling ad-blocking.
@@ -15898,7 +15986,7 @@ class BaseCase(unittest.TestCase):
15898
15986
  if self.undetectable:
15899
15987
  try:
15900
15988
  self.driver.window_handles
15901
- except urllib3.exceptions.MaxRetryError:
15989
+ except Exception:
15902
15990
  self.driver.connect()
15903
15991
  self.__slow_mode_pause_if_active()
15904
15992
  has_exception = self.__has_exception()
@@ -164,6 +164,7 @@ class MultiBrowser:
164
164
  CERT_FIXING_LOCK = Files.DOWNLOADS_FOLDER + "/cert_fixing.lock"
165
165
  DOWNLOAD_FILE_LOCK = Files.DOWNLOADS_FOLDER + "/downloading.lock"
166
166
  FILE_IO_LOCK = Files.DOWNLOADS_FOLDER + "/file_io.lock"
167
+ PYAUTOGUILOCK = Files.DOWNLOADS_FOLDER + "/pyautogui.lock"
167
168
 
168
169
 
169
170
  class SavedCookies:
@@ -354,6 +355,11 @@ class SeleniumWire:
354
355
  BLINKER_VER = "1.7.0" # The "blinker" dependency version
355
356
 
356
357
 
358
+ class PyAutoGUI:
359
+ # The version installed if PyAutoGUI is not installed
360
+ VER = "0.9.54"
361
+
362
+
357
363
  class Mobile:
358
364
  # Default values for mobile settings
359
365
  WIDTH = 390
@@ -1017,7 +1017,7 @@ def wait_for_element_not_visible(
1017
1017
  def wait_for_text_not_visible(
1018
1018
  driver,
1019
1019
  text,
1020
- selector,
1020
+ selector="html",
1021
1021
  by="css selector",
1022
1022
  timeout=settings.LARGE_TIMEOUT,
1023
1023
  ):
@@ -1060,7 +1060,7 @@ def wait_for_text_not_visible(
1060
1060
  def wait_for_exact_text_not_visible(
1061
1061
  driver,
1062
1062
  text,
1063
- selector,
1063
+ selector="html",
1064
1064
  by="css selector",
1065
1065
  timeout=settings.LARGE_TIMEOUT,
1066
1066
  ):
@@ -1686,19 +1686,50 @@ def assert_text(
1686
1686
  by="css selector",
1687
1687
  timeout=settings.SMALL_TIMEOUT,
1688
1688
  ):
1689
+ selector, by = page_utils.recalculate_selector(selector, by)
1689
1690
  wait_for_text_visible(
1690
1691
  driver, text.strip(), selector, by=by, timeout=timeout
1691
1692
  )
1692
1693
 
1693
1694
 
1694
1695
  def assert_exact_text(
1695
- driver, text, selector, by="css selector", timeout=settings.SMALL_TIMEOUT
1696
+ driver,
1697
+ text,
1698
+ selector="html",
1699
+ by="css selector",
1700
+ timeout=settings.SMALL_TIMEOUT,
1696
1701
  ):
1702
+ selector, by = page_utils.recalculate_selector(selector, by)
1697
1703
  wait_for_exact_text_visible(
1698
1704
  driver, text.strip(), selector, by=by, timeout=timeout
1699
1705
  )
1700
1706
 
1701
1707
 
1708
+ def assert_non_empty_text(
1709
+ driver,
1710
+ selector,
1711
+ by="css selector",
1712
+ timeout=settings.SMALL_TIMEOUT,
1713
+ ):
1714
+ selector, by = page_utils.recalculate_selector(selector, by)
1715
+ wait_for_non_empty_text_visible(
1716
+ driver, selector, by=by, timeout=timeout
1717
+ )
1718
+
1719
+
1720
+ def assert_text_not_visible(
1721
+ driver,
1722
+ text,
1723
+ selector="html",
1724
+ by="css selector",
1725
+ timeout=settings.SMALL_TIMEOUT,
1726
+ ):
1727
+ selector, by = page_utils.recalculate_selector(selector, by)
1728
+ wait_for_text_not_visible(
1729
+ driver, text.strip(), selector, by=by, timeout=timeout
1730
+ )
1731
+
1732
+
1702
1733
  def wait_for_element(
1703
1734
  driver,
1704
1735
  selector,
@@ -1748,6 +1779,7 @@ def wait_for_text(
1748
1779
  by="css selector",
1749
1780
  timeout=settings.LARGE_TIMEOUT,
1750
1781
  ):
1782
+ selector, by = page_utils.recalculate_selector(selector, by)
1751
1783
  return wait_for_text_visible(
1752
1784
  driver=driver,
1753
1785
  text=text,
@@ -1764,6 +1796,7 @@ def wait_for_exact_text(
1764
1796
  by="css selector",
1765
1797
  timeout=settings.LARGE_TIMEOUT,
1766
1798
  ):
1799
+ selector, by = page_utils.recalculate_selector(selector, by)
1767
1800
  return wait_for_exact_text_visible(
1768
1801
  driver=driver,
1769
1802
  text=text,
@@ -1779,6 +1812,7 @@ def wait_for_non_empty_text(
1779
1812
  by="css selector",
1780
1813
  timeout=settings.LARGE_TIMEOUT,
1781
1814
  ):
1815
+ selector, by = page_utils.recalculate_selector(selector, by)
1782
1816
  return wait_for_non_empty_text_visible(
1783
1817
  driver=driver,
1784
1818
  selector=selector,
@@ -103,7 +103,7 @@ function hasDigit(str) {
103
103
  return /\d/.test(str);
104
104
  };
105
105
  function isGen(str) {
106
- return /[_-]\d/.test(str);
106
+ return /[_-]\d/.test(str) || /\d[a-z]/.test(str);
107
107
  };
108
108
  function tagName(el) {
109
109
  return el.tagName.toLowerCase();
@@ -103,7 +103,7 @@ function hasDigit(str) {
103
103
  return /\d/.test(str);
104
104
  };
105
105
  function isGen(str) {
106
- return /[_-]\d/.test(str);
106
+ return /[_-]\d/.test(str) || /\d[a-z]/.test(str);
107
107
  };
108
108
  function tagName(el) {
109
109
  return el.tagName.toLowerCase();
@@ -36,6 +36,7 @@ driver.get("https://google.com/ncr")
36
36
 
37
37
  ###########################################################################
38
38
  """
39
+ import os
39
40
  import sys
40
41
 
41
42
 
@@ -124,6 +125,7 @@ def Driver(
124
125
  uc_cdp=None, # Shortcut / Duplicate of "uc_cdp_events".
125
126
  uc_sub=None, # Shortcut / Duplicate of "uc_subprocess".
126
127
  log_cdp=None, # Shortcut / Duplicate of "log_cdp_events".
128
+ server=None, # Shortcut / Duplicate of "servername".
127
129
  wire=None, # Shortcut / Duplicate of "use_wire".
128
130
  pls=None, # Shortcut / Duplicate of "page_load_strategy".
129
131
  ):
@@ -246,6 +248,8 @@ def Driver(
246
248
  headless2 = False
247
249
  if protocol is None:
248
250
  protocol = "http" # For the Selenium Grid only!
251
+ if server is not None and servername is None:
252
+ servername = server
249
253
  if servername is None:
250
254
  servername = "localhost" # For the Selenium Grid only!
251
255
  use_grid = False
@@ -328,37 +332,6 @@ def Driver(
328
332
  ):
329
333
  recorder_mode = True
330
334
  recorder_ext = True
331
- if headed is None:
332
- # Override the default headless mode on Linux if set.
333
- if "--gui" in sys_argv or "--headed" in sys_argv:
334
- headed = True
335
- else:
336
- headed = False
337
- if (
338
- shared_utils.is_linux()
339
- and not headed
340
- and not headless
341
- and not headless2
342
- ):
343
- headless = True
344
- if recorder_mode and headless:
345
- headless = False
346
- headless2 = True
347
- if headless2 and browser == "firefox":
348
- headless2 = False # Only for Chromium browsers
349
- headless = True # Firefox has regular headless
350
- elif browser not in ["chrome", "edge"]:
351
- headless2 = False # Only for Chromium browsers
352
- if disable_csp is None:
353
- disable_csp = False
354
- if (
355
- (enable_ws is None and disable_ws is None)
356
- or (disable_ws is not None and not disable_ws)
357
- or (enable_ws is not None and enable_ws)
358
- ):
359
- enable_ws = True
360
- else:
361
- enable_ws = False
362
335
  if (
363
336
  undetectable
364
337
  or undetected
@@ -414,6 +387,50 @@ def Driver(
414
387
  uc_cdp_events = True
415
388
  else:
416
389
  uc_cdp_events = False
390
+ if undetectable and browser != "chrome":
391
+ message = (
392
+ '\n Undetected-Chromedriver Mode ONLY supports Chrome!'
393
+ '\n ("uc=True" / "undetectable=True" / "--uc")'
394
+ '\n (Your browser choice was: "%s".)'
395
+ '\n (Will use "%s" without UC Mode.)\n' % (browser, browser)
396
+ )
397
+ print(message)
398
+ if headed is None:
399
+ # Override the default headless mode on Linux if set.
400
+ if "--gui" in sys_argv or "--headed" in sys_argv:
401
+ headed = True
402
+ else:
403
+ headed = False
404
+ if (
405
+ shared_utils.is_linux()
406
+ and not headed
407
+ and not headless
408
+ and not headless2
409
+ and (
410
+ not undetectable
411
+ or "DISPLAY" not in os.environ.keys()
412
+ or not os.environ["DISPLAY"]
413
+ )
414
+ ):
415
+ headless = True
416
+ if recorder_mode and headless:
417
+ headless = False
418
+ headless2 = True
419
+ if headless2 and browser == "firefox":
420
+ headless2 = False # Only for Chromium browsers
421
+ headless = True # Firefox has regular headless
422
+ elif browser not in ["chrome", "edge"]:
423
+ headless2 = False # Only for Chromium browsers
424
+ if disable_csp is None:
425
+ disable_csp = False
426
+ if (
427
+ (enable_ws is None and disable_ws is None)
428
+ or (disable_ws is not None and not disable_ws)
429
+ or (enable_ws is not None and enable_ws)
430
+ ):
431
+ enable_ws = True
432
+ else:
433
+ enable_ws = False
417
434
  if log_cdp_events is None and log_cdp is None:
418
435
  if (
419
436
  "--log-cdp-events" in sys_argv
@@ -1703,14 +1703,17 @@ def pytest_configure(config):
1703
1703
  and not sb_config.headless2
1704
1704
  and not sb_config.xvfb
1705
1705
  ):
1706
- print(
1707
- "(Linux uses --headless by default. "
1708
- "To override, use --headed / --gui. "
1709
- "For Xvfb mode instead, use --xvfb. "
1710
- "Or you can hide this info by using "
1711
- "--headless / --headless2.)"
1712
- )
1713
- sb_config.headless = True
1706
+ if not sb_config.undetectable:
1707
+ print(
1708
+ "(Linux uses --headless by default. "
1709
+ "To override, use --headed / --gui. "
1710
+ "For Xvfb mode instead, use --xvfb. "
1711
+ "Or you can hide this info by using "
1712
+ "--headless / --headless2 / --uc.)"
1713
+ )
1714
+ sb_config.headless = True
1715
+ else:
1716
+ sb_config.xvfb = True
1714
1717
 
1715
1718
  # Recorder Mode can still optimize scripts in --headless2 mode.
1716
1719
  if sb_config.recorder_mode and sb_config.headless:
@@ -103,6 +103,7 @@ def SB(
103
103
  uc_cdp=None, # Shortcut / Duplicate of "uc_cdp_events".
104
104
  uc_sub=None, # Shortcut / Duplicate of "uc_subprocess".
105
105
  log_cdp=None, # Shortcut / Duplicate of "log_cdp_events".
106
+ server=None, # Shortcut / Duplicate of "servername".
106
107
  wire=None, # Shortcut / Duplicate of "use_wire".
107
108
  pls=None, # Shortcut / Duplicate of "page_load_strategy".
108
109
  sjw=None, # Shortcut / Duplicate of "skip_js_waits".
@@ -282,6 +283,8 @@ def SB(
282
283
  headless2 = False
283
284
  if protocol is None:
284
285
  protocol = "http" # For the Selenium Grid only!
286
+ if server is not None and servername is None:
287
+ servername = server
285
288
  if servername is None:
286
289
  servername = "localhost" # For the Selenium Grid only!
287
290
  if port is None:
@@ -386,6 +389,69 @@ def SB(
386
389
  if not shared_utils.is_linux():
387
390
  # The Xvfb virtual display server is for Linux OS Only!
388
391
  xvfb = False
392
+ if (
393
+ undetectable
394
+ or undetected
395
+ or uc
396
+ or uc_cdp_events
397
+ or uc_cdp
398
+ or uc_subprocess
399
+ or uc_sub
400
+ ):
401
+ undetectable = True
402
+ if (
403
+ (undetectable or undetected or uc)
404
+ and (uc_subprocess is None)
405
+ and (uc_sub is None)
406
+ ):
407
+ uc_subprocess = True # Use UC as a subprocess by default.
408
+ elif (
409
+ "--undetectable" in sys_argv
410
+ or "--undetected" in sys_argv
411
+ or "--uc" in sys_argv
412
+ or "--uc-cdp-events" in sys_argv
413
+ or "--uc_cdp_events" in sys_argv
414
+ or "--uc-cdp" in sys_argv
415
+ or "--uc-subprocess" in sys_argv
416
+ or "--uc_subprocess" in sys_argv
417
+ or "--uc-sub" in sys_argv
418
+ ):
419
+ undetectable = True
420
+ if uc_subprocess is None and uc_sub is None:
421
+ uc_subprocess = True # Use UC as a subprocess by default.
422
+ else:
423
+ undetectable = False
424
+ if uc_subprocess or uc_sub:
425
+ uc_subprocess = True
426
+ elif (
427
+ "--uc-subprocess" in sys_argv
428
+ or "--uc_subprocess" in sys_argv
429
+ or "--uc-sub" in sys_argv
430
+ ):
431
+ uc_subprocess = True
432
+ else:
433
+ uc_subprocess = False
434
+ if uc_cdp_events or uc_cdp:
435
+ undetectable = True
436
+ uc_cdp_events = True
437
+ elif (
438
+ "--uc-cdp-events" in sys_argv
439
+ or "--uc_cdp_events" in sys_argv
440
+ or "--uc-cdp" in sys_argv
441
+ or "--uc_cdp" in sys_argv
442
+ ):
443
+ undetectable = True
444
+ uc_cdp_events = True
445
+ else:
446
+ uc_cdp_events = False
447
+ if undetectable and browser != "chrome":
448
+ message = (
449
+ '\n Undetected-Chromedriver Mode ONLY supports Chrome!'
450
+ '\n ("uc=True" / "undetectable=True" / "--uc")'
451
+ '\n (Your browser choice was: "%s".)'
452
+ '\n (Will use "%s" without UC Mode.)\n' % (browser, browser)
453
+ )
454
+ print(message)
389
455
  if headed is None:
390
456
  # Override the default headless mode on Linux if set.
391
457
  if "--gui" in sys_argv or "--headed" in sys_argv:
@@ -399,7 +465,10 @@ def SB(
399
465
  and not headless2
400
466
  and not xvfb
401
467
  ):
402
- headless = True
468
+ if not undetectable:
469
+ headless = True
470
+ else:
471
+ xvfb = True
403
472
  if headless2 and browser == "firefox":
404
473
  headless2 = False # Only for Chromium browsers
405
474
  headless = True # Firefox has regular headless
@@ -456,61 +525,6 @@ def SB(
456
525
  else:
457
526
  enable_ws = False
458
527
  disable_ws = True
459
- if (
460
- undetectable
461
- or undetected
462
- or uc
463
- or uc_cdp_events
464
- or uc_cdp
465
- or uc_subprocess
466
- or uc_sub
467
- ):
468
- undetectable = True
469
- if (
470
- (undetectable or undetected or uc)
471
- and (uc_subprocess is None)
472
- and (uc_sub is None)
473
- ):
474
- uc_subprocess = True # Use UC as a subprocess by default.
475
- elif (
476
- "--undetectable" in sys_argv
477
- or "--undetected" in sys_argv
478
- or "--uc" in sys_argv
479
- or "--uc-cdp-events" in sys_argv
480
- or "--uc_cdp_events" in sys_argv
481
- or "--uc-cdp" in sys_argv
482
- or "--uc-subprocess" in sys_argv
483
- or "--uc_subprocess" in sys_argv
484
- or "--uc-sub" in sys_argv
485
- ):
486
- undetectable = True
487
- if uc_subprocess is None and uc_sub is None:
488
- uc_subprocess = True # Use UC as a subprocess by default.
489
- else:
490
- undetectable = False
491
- if uc_subprocess or uc_sub:
492
- uc_subprocess = True
493
- elif (
494
- "--uc-subprocess" in sys_argv
495
- or "--uc_subprocess" in sys_argv
496
- or "--uc-sub" in sys_argv
497
- ):
498
- uc_subprocess = True
499
- else:
500
- uc_subprocess = False
501
- if uc_cdp_events or uc_cdp:
502
- undetectable = True
503
- uc_cdp_events = True
504
- elif (
505
- "--uc-cdp-events" in sys_argv
506
- or "--uc_cdp_events" in sys_argv
507
- or "--uc-cdp" in sys_argv
508
- or "--uc_cdp" in sys_argv
509
- ):
510
- undetectable = True
511
- uc_cdp_events = True
512
- else:
513
- uc_cdp_events = False
514
528
  if log_cdp_events is None and log_cdp is None:
515
529
  if (
516
530
  "--log-cdp-events" in sys_argv
@@ -1204,15 +1204,19 @@ class SeleniumBrowser(Plugin):
1204
1204
  and not self.options.headless2
1205
1205
  and not self.options.xvfb
1206
1206
  ):
1207
- print(
1208
- "(Linux uses --headless by default. "
1209
- "To override, use --headed / --gui. "
1210
- "For Xvfb mode instead, use --xvfb. "
1211
- "Or you can hide this info by using "
1212
- "--headless / --headless2.)"
1213
- )
1214
- self.options.headless = True
1215
- test.test.headless = True
1207
+ if not self.options.undetectable:
1208
+ print(
1209
+ "(Linux uses --headless by default. "
1210
+ "To override, use --headed / --gui. "
1211
+ "For Xvfb mode instead, use --xvfb. "
1212
+ "Or you can hide this info by using "
1213
+ "--headless / --headless2 / --uc.)"
1214
+ )
1215
+ self.options.headless = True
1216
+ test.test.headless = True
1217
+ else:
1218
+ self.options.xvfb = True
1219
+ test.test.xvfb = True
1216
1220
  if self.options.use_wire and self.options.undetectable:
1217
1221
  print(
1218
1222
  "\n"