Skip to content

Commit 533c12f

Browse files
committed
Update UC Mode
1 parent 39d54e4 commit 533c12f

File tree

5 files changed

+45
-3
lines changed

5 files changed

+45
-3
lines changed

help_docs/method_summary.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,8 @@ driver.uc_open_with_tab(url) # (New tab with default reconnect_time)
10461046

10471047
driver.uc_open_with_reconnect(url, reconnect_time=None) # (New tab)
10481048

1049+
driver.uc_open_with_disconnect(url) # Open in new tab + disconnect()
1050+
10491051
driver.reconnect(timeout) # disconnect() + sleep(timeout) + connect()
10501052

10511053
driver.disconnect() # Stops the webdriver service to prevent detection

help_docs/uc_mode.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ driver.uc_open_with_tab(url)
159159

160160
driver.uc_open_with_reconnect(url, reconnect_time=None)
161161

162+
driver.uc_open_with_disconnect(url)
163+
162164
driver.reconnect(timeout)
163165

164166
driver.disconnect()

seleniumbase/core/browser_launcher.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,32 @@ def uc_open_with_reconnect(driver, url, reconnect_time=None):
443443
js_utils.call_me_later(driver, script, 3)
444444
time.sleep(0.007)
445445
driver.close()
446-
driver.reconnect(reconnect_time)
447-
driver.switch_to.window(driver.window_handles[-1])
446+
if reconnect_time == "disconnect":
447+
driver.disconnect()
448+
time.sleep(0.007)
449+
else:
450+
driver.reconnect(reconnect_time)
451+
driver.switch_to.window(driver.window_handles[-1])
452+
else:
453+
driver.default_get(url) # The original one
454+
return None
455+
456+
457+
def uc_open_with_disconnect(driver, url):
458+
"""Open a url and disconnect chromedriver.
459+
Note: You can't perform Selenium actions again
460+
until after you've called driver.connect()."""
461+
if url.startswith("//"):
462+
url = "https:" + url
463+
elif ":" not in url:
464+
url = "https://" + url
465+
if (url.startswith("http:") or url.startswith("https:")):
466+
script = 'window.open("%s","_blank");' % url
467+
js_utils.call_me_later(driver, script, 3)
468+
time.sleep(0.007)
469+
driver.close()
470+
driver.disconnect()
471+
time.sleep(0.007)
448472
else:
449473
driver.default_get(url) # The original one
450474
return None
@@ -3754,6 +3778,11 @@ def get_local_driver(
37543778
driver, *args, **kwargs
37553779
)
37563780
)
3781+
driver.uc_open_with_disconnect = (
3782+
lambda *args, **kwargs: uc_open_with_disconnect(
3783+
driver, *args, **kwargs
3784+
)
3785+
)
37573786
driver.uc_click = lambda *args, **kwargs: uc_click(
37583787
driver, *args, **kwargs
37593788
)

seleniumbase/fixtures/base_case.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4146,6 +4146,10 @@ def get_new_driver(
41464146
self.uc_open_with_tab = new_driver.uc_open_with_tab
41474147
if hasattr(new_driver, "uc_open_with_reconnect"):
41484148
self.uc_open_with_reconnect = new_driver.uc_open_with_reconnect
4149+
if hasattr(new_driver, "uc_open_with_disconnect"):
4150+
self.uc_open_with_disconnect = (
4151+
new_driver.uc_open_with_disconnect
4152+
)
41494153
if hasattr(new_driver, "reconnect"):
41504154
self.reconnect = new_driver.reconnect
41514155
if hasattr(new_driver, "disconnect"):
@@ -15886,6 +15890,11 @@ def tearDown(self):
1588615890
)
1588715891
raise Exception(message)
1588815892
# *** Start tearDown() officially ***
15893+
if self.undetectable:
15894+
try:
15895+
self.driver.window_handles
15896+
except urllib3.exceptions.MaxRetryError:
15897+
self.driver.connect()
1588915898
self.__slow_mode_pause_if_active()
1589015899
has_exception = self.__has_exception()
1589115900
sb_config._has_exception = has_exception

seleniumbase/undetected/webelement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def uc_click(
1414
):
1515
if driver and selector and by:
1616
delayed_click = False
17-
if tag_name in ["span", "button", "div", "a"]:
17+
if tag_name in ["span", "button", "div", "a", "b", "input"]:
1818
delayed_click = True
1919
if delayed_click and ":contains" not in selector:
2020
selector = js_utils.convert_to_css_selector(selector, by)

0 commit comments

Comments
 (0)