Skip to content

Commit fb24362

Browse files
authored
Merge pull request #2544 from seleniumbase/mostly-uc-mode-updates
Mostly UC Mode updates
2 parents 5d9fdc0 + c521e82 commit fb24362

14 files changed

+84
-47
lines changed

examples/offline_examples/test_demo_page.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def test_demo_page(self):
3434
try:
3535
self.hover_and_click("#myDropdown", "#dropOption2", timeout=1)
3636
except Exception:
37-
# Someone moved the mouse while the test ran
38-
self.js_click("#dropOption2")
37+
# Someone probably moved the mouse while the test ran
38+
self.hover_and_js_click("#myDropdown", "#dropOption2")
3939
self.assert_text("Link Two Selected", "h3")
4040

4141
# Click a button and then verify the expected results

examples/raw_form_turnstile.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33

44
def open_the_form_turnstile_page(sb):
55
sb.driver.uc_open_with_reconnect(
6-
"https://seleniumbase.io/apps/form_turnstile", reconnect_time=2.5,
6+
"https://seleniumbase.io/apps/form_turnstile", reconnect_time=2.7,
77
)
88

99

1010
def click_turnstile_and_verify(sb):
11+
sb.scroll_to_bottom()
1112
sb.driver.uc_switch_to_frame("iframe")
1213
sb.driver.uc_click("span.mark")
1314
sb.highlight("img#captcha-success", timeout=3.33)

examples/raw_nopecha.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from seleniumbase import SB
2+
3+
with SB(uc=True, test=True) as sb:
4+
sb.driver.uc_open_with_reconnect("https://nopecha.com/demo/turnstile", 5)
5+
sb.driver.uc_switch_to_frame("#example-container5 iframe")
6+
sb.driver.uc_click("span.mark")
7+
8+
if sb.is_element_visible("#example-container0 iframe"):
9+
sb.switch_to_frame("#example-container0 iframe")
10+
if not sb.is_element_visible("circle.success-circle"):
11+
sb.driver.uc_click("span.mark")
12+
sb.switch_to_frame("#example-container0 iframe")
13+
sb.assert_element("circle.success-circle")
14+
sb.switch_to_parent_frame()
15+
sb.switch_to_frame("#example-container5 iframe")
16+
sb.assert_element("svg#success-icon", timeout=3)
17+
sb.switch_to_parent_frame()
18+
sb.set_messenger_theme(location="top_center")
19+
sb.post_message("Selenium wasn't detected!", duration=3)

examples/raw_pixelscan.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from seleniumbase import SB
2+
3+
with SB(uc=True, incognito=True, test=True) as sb:
4+
sb.driver.uc_open_with_reconnect("https://pixelscan.net/", 11)
5+
sb.remove_elements("jdiv") # Remove chat widgets
6+
sb.assert_text("No automation framework detected", "pxlscn-bot-detection")
7+
sb.assert_text("You are not masking your fingerprint")
8+
sb.highlight("span.text-success", loops=10)
9+
sb.sleep(1)
10+
sb.highlight("pxlscn-fingerprint-masking div", loops=10, scroll=False)
11+
sb.sleep(1)
12+
sb.highlight("div.bot-detection-context", loops=10, scroll=False)
13+
sb.sleep(3)

examples/raw_turnstile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
def open_the_turnstile_page(sb):
55
sb.driver.uc_open_with_reconnect(
6-
"https://seleniumbase.io/apps/turnstile", reconnect_time=2.5,
6+
"https://seleniumbase.io/apps/turnstile", reconnect_time=2.7,
77
)
88

99

examples/raw_uc_mode.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
from seleniumbase import SB
33

44
with SB(uc=True, test=True) as sb:
5-
sb.driver.uc_open_with_reconnect("https://top.gg/", 4)
5+
sb.driver.uc_open_with_reconnect("https://top.gg/", 5)
66
if not sb.is_text_visible("Discord Bots", "h1"):
7-
sb.get_new_driver(undetectable=True)
87
sb.driver.uc_open_with_reconnect("https://top.gg/", 5)
9-
sb.activate_demo_mode() # Highlight + show assertions
108
sb.assert_text("Discord Bots", "h1", timeout=3)
9+
sb.highlight("h1", loops=3)
10+
sb.set_messenger_theme(location="top_center")
11+
sb.post_message("Selenium wasn't detected!", duration=3)

examples/test_demo_site.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def test_demo_site(self):
2929
try:
3030
self.hover_and_click("#myDropdown", "#dropOption2", timeout=1)
3131
except Exception:
32-
# Someone moved the mouse while the test ran
33-
self.js_click("#dropOption2")
32+
# Someone probably moved the mouse while the test ran
33+
self.hover_and_js_click("#myDropdown", "#dropOption2")
3434
self.assert_text("Link Two Selected", "h3")
3535

3636
# Click a button and then verify the expected results

examples/verify_undetected.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@ class UndetectedTest(BaseCase):
99
def test_browser_is_undetected(self):
1010
if not self.undetectable:
1111
self.get_new_driver(undetectable=True)
12-
self.driver.uc_open_with_reconnect(
13-
"https://top.gg/", reconnect_time=4
14-
)
12+
self.driver.uc_open_with_reconnect("https://top.gg/", 5)
1513
if not self.is_text_visible("Discord Bots", "h1"):
1614
self.get_new_driver(undetectable=True)
17-
self.driver.uc_open_with_reconnect(
18-
"https://top.gg/", reconnect_time=5
19-
)
15+
self.driver.uc_open_with_reconnect("https://top.gg/", 5)
2016
self.assert_text("Discord Bots", "h1", timeout=3)
21-
self.set_messenger_theme(theme="air", location="top_center")
17+
self.set_messenger_theme(location="top_center")
2218
self.post_message("Selenium wasn't detected!", duration=2.8)
2319
self._print("\n Success! Website did not detect Selenium! ")

help_docs/method_summary.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ driver.uc_click(
10191019
selector, by="css selector",
10201020
timeout=settings.SMALL_TIMEOUT, reconnect_time=None)
10211021

1022-
driver.uc_switch_to_frame(frame)
1022+
driver.uc_switch_to_frame(frame, reconnect_time=None)
10231023
```
10241024

10251025
--------

help_docs/uc_mode.md

+11-19
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from seleniumbase import Driver
2626

2727
driver = Driver(uc=True)
28-
driver.uc_open_with_reconnect("https://nowsecure.nl/#relax", 5)
28+
driver.uc_open_with_reconnect("https://top.gg/", 6)
2929
driver.quit()
3030
```
3131

@@ -35,30 +35,22 @@ driver.quit()
3535
from seleniumbase import SB
3636

3737
with SB(uc=True) as sb:
38-
sb.driver.uc_open_with_reconnect("https://nowsecure.nl/#relax", 5)
38+
sb.driver.uc_open_with_reconnect("https://top.gg/", 6)
3939
```
4040

41-
👤 Here's a longer example, which includes retries and a captcha-click failsafe for bypassing detection:
41+
👤 Here's a longer example, which includes a retry if the CAPTCHA isn't bypassed on the first attempt:
4242

4343
```python
4444
from seleniumbase import SB
4545

4646
with SB(uc=True, test=True) as sb:
47-
sb.driver.uc_open_with_tab("https://nowsecure.nl/#relax")
48-
sb.sleep(1.2)
49-
if not sb.is_text_visible("OH YEAH, you passed!", "h1"):
50-
sb.get_new_driver(undetectable=True)
51-
sb.driver.uc_open_with_reconnect(
52-
"https://nowsecure.nl/#relax", reconnect_time=3
53-
)
54-
sb.sleep(1.2)
55-
if not sb.is_text_visible("OH YEAH, you passed!", "h1"):
56-
if sb.is_element_visible('iframe[src*="challenge"]'):
57-
with sb.frame_switch('iframe[src*="challenge"]'):
58-
sb.click("span.mark")
59-
sb.sleep(2)
60-
sb.activate_demo_mode()
61-
sb.assert_text("OH YEAH, you passed!", "h1", timeout=3)
47+
sb.driver.uc_open_with_reconnect("https://top.gg/", 5)
48+
if not sb.is_text_visible("Discord Bots", "h1"):
49+
sb.driver.uc_open_with_reconnect("https://top.gg/", 5)
50+
sb.assert_text("Discord Bots", "h1", timeout=3)
51+
sb.highlight("h1", loops=3)
52+
sb.set_messenger_theme(location="top_center")
53+
sb.post_message("Selenium wasn't detected!", duration=3)
6254
```
6355

6456
👤 Here's an example where clicking the checkbox is required, even for humans: (Commonly seen with forms that are CAPTCHA-protected.)
@@ -111,7 +103,7 @@ driver.uc_click(
111103
selector, by="css selector",
112104
timeout=settings.SMALL_TIMEOUT, reconnect_time=None)
113105

114-
driver.uc_switch_to_frame(frame)
106+
driver.uc_switch_to_frame(frame, reconnect_time=None)
115107
```
116108

117109
(Note that the `reconnect_time` is used to specify how long the driver should be disconnected from Chrome to prevent detection before reconnecting again.)

seleniumbase/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "4.24.1"
2+
__version__ = "4.24.2"

seleniumbase/console_scripts/sb_mkdir.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,9 @@ def main():
381381
' self.assert_text("Typing Text!", \'[name="preText2"]\')'
382382
)
383383
data.append(' self.assert_text("Automation Practice", "h3")')
384-
data.append(" try:")
385-
data.append(" self.hover_and_click(")
386-
data.append(' "#myDropdown", "#dropOption2", timeout=1)')
387-
data.append(" except Exception:")
388-
data.append(" # Someone moved the mouse while the test ran")
389-
data.append(' self.js_click("#dropOption2")')
384+
data.append(
385+
' self.hover_and_js_click("#myDropdown", "#dropOption2")'
386+
)
390387
data.append(' self.assert_text("Link Two Selected", "h3")')
391388
data.append(' self.assert_text("This Text is Green", "#pText")')
392389
data.append(' self.click("#myButton")')

seleniumbase/core/browser_launcher.py

+21-3
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,10 @@ def uc_special_open_if_cf(
397397

398398

399399
def uc_open(driver, url):
400+
if url.startswith("//"):
401+
url = "https:" + url
402+
elif ":" not in url:
403+
url = "https://" + url
400404
if (url.startswith("http:") or url.startswith("https:")):
401405
time.sleep(0.05)
402406
with driver:
@@ -407,6 +411,10 @@ def uc_open(driver, url):
407411

408412

409413
def uc_open_with_tab(driver, url):
414+
if url.startswith("//"):
415+
url = "https:" + url
416+
elif ":" not in url:
417+
url = "https://" + url
410418
if (url.startswith("http:") or url.startswith("https:")):
411419
time.sleep(0.05)
412420
with driver:
@@ -422,6 +430,10 @@ def uc_open_with_reconnect(driver, url, reconnect_time=None):
422430
"""Open a url, disconnect chromedriver, wait, and reconnect."""
423431
if not reconnect_time:
424432
reconnect_time = constants.UC.RECONNECT_TIME
433+
if url.startswith("//"):
434+
url = "https:" + url
435+
elif ":" not in url:
436+
url = "https://" + url
425437
if (url.startswith("http:") or url.startswith("https:")):
426438
driver.execute_script('window.open("%s","_blank");' % url)
427439
driver.close()
@@ -455,14 +467,20 @@ def uc_click(
455467
driver.js_click(selector, by=by, timeout=timeout)
456468

457469

458-
def uc_switch_to_frame(driver, frame):
470+
def uc_switch_to_frame(driver, frame, reconnect_time=None):
459471
from selenium.webdriver.remote.webelement import WebElement
460472
if isinstance(frame, WebElement):
461-
driver.reconnect(0.15)
473+
if not reconnect_time:
474+
driver.reconnect(0.15)
475+
else:
476+
driver.reconnect(reconnect_time)
462477
driver.switch_to.frame(frame)
463478
else:
464479
iframe = driver.locator(frame)
465-
driver.reconnect(0.15)
480+
if not reconnect_time:
481+
driver.reconnect(0.15)
482+
else:
483+
driver.reconnect(reconnect_time)
466484
driver.switch_to.frame(iframe)
467485

468486

seleniumbase/undetected/webelement.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def uc_click(
1414
else:
1515
super().click()
1616
if not reconnect_time:
17-
self._parent.reconnect(0.1)
17+
self._parent.reconnect(0.45)
1818
else:
1919
self._parent.reconnect(reconnect_time)
2020

0 commit comments

Comments
 (0)