Skip to content

Commit f67449a

Browse files
committed
Update UC Mode examples
1 parent 197cf5f commit f67449a

File tree

5 files changed

+14
-38
lines changed

5 files changed

+14
-38
lines changed

examples/raw_cdp_logging.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
try:
66
url = "seleniumbase.io/apps/turnstile"
77
driver.uc_open_with_reconnect(url, 2)
8-
driver.switch_to_frame("iframe")
9-
driver.uc_click("span")
8+
driver.uc_gui_handle_cf()
109
driver.sleep(3)
1110
pprint(driver.get_log("performance"))
1211
finally:

examples/raw_form_turnstile.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
with SB(uc=True, test=True) as sb:
44
url = "seleniumbase.io/apps/form_turnstile"
5-
sb.driver.uc_open_with_reconnect(url, 2)
5+
sb.uc_open_with_reconnect(url, 2)
66
sb.press_keys("#name", "SeleniumBase")
77
sb.press_keys("#email", "test@test.test")
88
sb.press_keys("#phone", "1-555-555-5555")
@@ -12,8 +12,8 @@
1212
sb.click('span:contains("9:00 PM")')
1313
sb.highlight_click('input[value="AR"] + span')
1414
sb.click('input[value="cc"] + span')
15-
sb.switch_to_frame("iframe")
16-
sb.driver.uc_click("span")
15+
sb.scroll_to("iframe")
16+
sb.uc_gui_handle_cf()
1717
sb.highlight("img#captcha-success", timeout=3)
1818
sb.highlight_click('button:contains("Request & Pay")')
1919
sb.highlight("img#submit-success")

examples/raw_nopecha.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
from seleniumbase import SB
22

33
with SB(uc=True, test=True) as sb:
4-
sb.driver.uc_open_with_reconnect("nopecha.com/demo/turnstile", 4)
5-
if sb.is_element_visible("#example-container0 iframe"):
6-
sb.switch_to_frame("#example-container0 iframe")
7-
if not sb.is_element_visible("circle.success-circle"):
8-
sb.driver.uc_click("span", reconnect_time=3)
9-
sb.switch_to_frame("#example-container0 iframe")
10-
sb.switch_to_default_content()
11-
12-
sb.switch_to_frame("#example-container5 iframe")
13-
sb.driver.uc_click("span", reconnect_time=2.5)
14-
sb.switch_to_frame("#example-container5 iframe")
15-
sb.assert_element("svg#success-icon", timeout=3)
16-
sb.switch_to_parent_frame()
4+
sb.uc_open_with_disconnect("nopecha.com/demo/turnstile", 3.5)
5+
sb.uc_gui_press_keys("\t\t ")
6+
sb.sleep(3.5)
7+
sb.connect()
8+
sb.uc_gui_handle_cf("#example-container5 iframe")
179

1810
if sb.is_element_visible("#example-container0 iframe"):
1911
sb.switch_to_frame("#example-container0 iframe")

examples/raw_turnstile.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,9 @@
11
from seleniumbase import SB
22

3-
4-
def open_the_turnstile_page(sb):
3+
with SB(uc=True, test=True) as sb:
54
url = "seleniumbase.io/apps/turnstile"
6-
sb.driver.uc_open_with_reconnect(url, reconnect_time=2)
7-
8-
9-
def click_turnstile_and_verify(sb):
10-
sb.driver.switch_to_frame("iframe")
11-
sb.driver.uc_click("span")
5+
sb.uc_open_with_reconnect(url, reconnect_time=2)
6+
sb.uc_gui_handle_cf()
127
sb.assert_element("img#captcha-success", timeout=3)
13-
14-
15-
with SB(uc=True, test=True) as sb:
16-
open_the_turnstile_page(sb)
17-
try:
18-
click_turnstile_and_verify(sb)
19-
except Exception:
20-
open_the_turnstile_page(sb)
21-
click_turnstile_and_verify(sb)
228
sb.set_messenger_theme(location="top_left")
239
sb.post_message("SeleniumBase wasn't detected", duration=3)

examples/uc_cdp_events.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@ def add_cdp_listener(self):
1313
)
1414

1515
def click_turnstile_and_verify(sb):
16-
sb.switch_to_frame("iframe")
17-
sb.driver.uc_click("span")
16+
sb.uc_gui_handle_cf()
1817
sb.assert_element("img#captcha-success", timeout=3)
1918
sb.highlight("img#captcha-success", loops=8)
2019

2120
def test_display_cdp_events(self):
2221
if not (self.undetectable and self.uc_cdp_events):
2322
self.get_new_driver(undetectable=True, uc_cdp_events=True)
2423
url = "seleniumbase.io/apps/turnstile"
25-
self.driver.uc_open_with_reconnect(url, 2)
24+
self.uc_open_with_reconnect(url, 2)
2625
self.add_cdp_listener()
2726
self.click_turnstile_and_verify()
2827
self.sleep(1)

0 commit comments

Comments
 (0)