Skip to content

Commit 1e7355f

Browse files
committed
Update CDP Mode examples
1 parent 2706528 commit 1e7355f

File tree

7 files changed

+49
-3
lines changed

7 files changed

+49
-3
lines changed

examples/cdp_mode/raw_ahrefs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
sb.type(input_field, "github.com/seleniumbase/SeleniumBase")
99
sb.cdp.scroll_down(36)
1010
sb.click(submit_button)
11+
sb.sleep(1)
1112
sb.uc_gui_click_captcha()
13+
sb.sleep(3)
1214
sb.wait_for_text_not_visible("Checking", timeout=15)
1315
sb.click_if_visible('button[data-cky-tag="close-button"]')
1416
sb.highlight('p:contains("github.com/seleniumbase/SeleniumBase")')

examples/cdp_mode/raw_copilot.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from seleniumbase import SB
2+
3+
with SB(uc=True, test=True, guest=True) as sb:
4+
url = "https://copilot.microsoft.com/"
5+
sb.activate_cdp_mode(url)
6+
textarea = "textarea#userInput"
7+
sb.wait_for_element(textarea)
8+
sb.sleep(1.5)
9+
sb.click_if_visible('[aria-label="Dismiss"]')
10+
sb.sleep(0.5)
11+
sb.click('button[data-testid*="chat-mode-"]')
12+
sb.sleep(1.1)
13+
sb.click('button[title="Think Deeper"]')
14+
sb.sleep(1.1)
15+
query = "How to migrate from Playwright to SeleniumBase?"
16+
sb.press_keys(textarea, query)
17+
sb.sleep(1.1)
18+
sb.click('button[data-testid="submit-button"]')
19+
sb.sleep(2.5)
20+
sb.uc_gui_click_captcha()
21+
sb.sleep(2.5)
22+
sb.uc_gui_click_captcha()
23+
sb.sleep(2.5)
24+
stop_button = '[data-testid="stop-button"]'
25+
thumbs_up = 'button[data-testid*="-thumbs-up-"]'
26+
sb.wait_for_element_absent(stop_button, timeout=30)
27+
sb.wait_for_element(thumbs_up, timeout=30)
28+
sb.sleep(0.5)
29+
sb.click('button[data-testid*="scroll-to-bottom"]')
30+
sb.sleep(1.5)
31+
folder = "downloaded_files"
32+
file_name = "copilot_results.html"
33+
sb.save_page_source(file_name, folder)
34+
print('"./%s/%s" was saved!' % (folder, file_name))

examples/cdp_mode/raw_gitlab.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
sb.activate_cdp_mode(url)
66
sb.sleep(2.2)
77
sb.uc_gui_click_captcha()
8+
# (The rest is for testing and demo purposes)
89
sb.assert_text("Username", '[for="user_login"]', timeout=3)
910
sb.assert_element('label[for="user_login"]')
1011
sb.highlight('button:contains("Sign in")')

examples/cdp_mode/raw_multi_captcha.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
def main(url):
99
sb = sb_cdp.Chrome(url, lang="en")
1010
sb.set_window_rect(randint(4, 680), randint(8, 380), 840, 520)
11-
sb.sleep(2.2)
11+
sb.sleep(2)
1212
sb.gui_click_captcha()
1313
sb.sleep(2)
1414
sb.driver.quit()

examples/cdp_mode/raw_planetmc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
url = "www.planetminecraft.com/account/sign_in/"
55
sb.activate_cdp_mode(url)
66
sb.sleep(2)
7-
sb.cdp.gui_click_element("#turnstile-widget div")
7+
sb.uc_gui_click_captcha()
88
sb.sleep(2)

examples/cdp_mode/raw_turnstile.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from seleniumbase import SB
2+
3+
with SB(uc=True, test=True) as sb:
4+
url = "https://seleniumbase.io/apps/turnstile"
5+
sb.activate_cdp_mode(url)
6+
sb.uc_gui_click_captcha()
7+
sb.assert_element("img#captcha-success", timeout=3)
8+
sb.set_messenger_theme(location="top_left")
9+
sb.post_message("SeleniumBase wasn't detected", duration=3)

examples/cdp_mode/raw_united.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
part_3 = flight.text.split(" Destination")[-1].split(" Aircraft")[0]
3636
parts = "%s - %s %s" % (part_1, part_2, part_3)
3737
print("* " + parts)
38-
for category in ["ECO-BASIC", "ECONOMY"]:
38+
for category in ["ECONOMY", "ECONOMY-UNRESTRICTED"]:
3939
prices = sb.find_elements('[aria-describedby="%s"]' % category)
4040
full_prices = []
4141
for item in prices:

0 commit comments

Comments
 (0)