Skip to content

Commit 41666ae

Browse files
committed
Update examples
1 parent b8686dc commit 41666ae

25 files changed

Lines changed: 97 additions & 61 deletions

examples/cdp_mode/raw_ad_blocking.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Test Ad-Blocking using mycdp.network.set_blocked_urls().
2+
tab.send() is the stealthy version of execute_cdp_cmd()."""
13
import mycdp
24
from seleniumbase import decorators
35
from seleniumbase import sb_cdp
@@ -28,4 +30,4 @@ async def block_urls(tab):
2830
sb.assert_false("doubleclick.net" in source)
2931
sb.assert_false("google-analytics.com" in source)
3032
sb.post_message("Blocking was successful!")
31-
sb.driver.quit()
33+
sb.quit()

examples/cdp_mode/raw_antibot.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
"""CDP Mode bypasses bot-detection and performs stealthy actions.
2+
sb.press_keys() is a slower sb.type() for human-like speed."""
13
from seleniumbase import SB
24

35
with SB(uc=True, test=True) as sb:
46
url = "https://seleniumbase.io/antibot/login"
57
sb.activate_cdp_mode(url)
68
sb.press_keys("input#username", "demo_user")
7-
sb.press_keys("input#password", "secret_pass")
9+
sb.type("input#password", "secret_pass")
810
sb.click("button#myButton")
9-
sb.sleep(1.5)
11+
sb.sleep(1.4)
1012
sb.click("a#log-in")
1113
sb.assert_text("Welcome!", "h1")
1214
sb.set_messenger_theme(location="bottom_center")
1315
sb.post_message("SeleniumBase wasn't detected!")
14-
sb.sleep(1.5)

examples/cdp_mode/raw_basic_cdp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from seleniumbase import sb_cdp
22

3-
url = "https://seleniumbase.io/simple/login"
4-
sb = sb_cdp.Chrome(url)
3+
sb = sb_cdp.Chrome()
4+
sb.open("https://seleniumbase.io/simple/login")
55
sb.type("#username", "demo_user")
66
sb.type("#password", "secret_pass")
77
sb.click('a:contains("Sign in")')
@@ -14,4 +14,4 @@
1414
print(nav_item.text)
1515
sb.click_link("Sign out")
1616
sb.assert_text("signed out", "#top_message")
17-
sb.driver.stop()
17+
sb.quit()

examples/cdp_mode/raw_cdp_pixelscan.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from seleniumbase import sb_cdp
22

3-
sb = sb_cdp.Chrome(incognito=True)
3+
sb = sb_cdp.Chrome(guest=True, ad_block=True)
44
sb.open("https://pixelscan.net/fingerprint-check")
55
sb.sleep(1)
66
sb.wait_for_element("pxlscn-dynamic-ad")
@@ -13,3 +13,4 @@
1313
sb.highlight("span.status-success")
1414
sb.highlight("pxlscn-fingerprint-masking p")
1515
sb.highlight("pxlscn-bot-detection p")
16+
print("Bot Not Detected")

examples/cdp_mode/raw_cdp_tavus.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from seleniumbase import sb_cdp
2+
3+
sb = sb_cdp.Chrome()
4+
sb.open("platform.tavus.io/auth/sign-in?is_developer=true")
5+
sb.sleep(3)
6+
sb.solve_captcha()
7+
sb.sleep(1)
8+
sb.assert_element('input[type="email"]')
9+
sb.assert_element('button[type="submit"]')

examples/cdp_mode/raw_cdp_walmart.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@
4343
price_text = price_text.split("current price ")[-1]
4444
price_text = price_text.split(" ")[0]
4545
print(" (" + price_text + ")")
46+
item.scroll_into_view()
4647
sb.driver.stop()

examples/cdp_mode/raw_cf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
"""Using CDP Mode to bypass CAPTCHAs in different ways."""
1+
"""Using CDP Mode to bypass CAPTCHAs in different ways.
2+
PyAutoGUI is installed automatically if not already."""
23
from seleniumbase import SB
34

45
with SB(uc=True, test=True, guest=True) as sb:

examples/cdp_mode/raw_mfa_login.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from seleniumbase import sb_cdp
22

3-
url = "https://seleniumbase.io/realworld/login"
4-
sb = sb_cdp.Chrome(url)
3+
sb = sb_cdp.Chrome()
4+
sb.open("https://seleniumbase.io/realworld/login")
55
sb.type("#username", "demo_user")
66
sb.type("#password", "secret_pass")
77
sb.enter_mfa_code("#totpcode", "GAXG2MTEOR3DMMDG")
88
sb.assert_text("Welcome!", "h1")
99
sb.click('a:contains("This Page")')
1010
sb.highlight("h1")
1111
sb.highlight("img#image1")
12-
sb.driver.stop()
12+
sb.quit()

examples/cdp_mode/raw_mobile_roblox.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Test mobile emulation via mycdp.emulation.set_device_metrics_override().
2+
tab.send() is a stealthy version of Selenium's execute_cdp_cmd() method."""
13
import mycdp
24
from seleniumbase import SB
35

examples/cdp_mode/raw_multi_cdp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def main(url):
1212
sb.highlight("button")
1313
sb.click("button")
1414
sb.sleep(2)
15-
sb.driver.quit()
15+
sb.quit()
1616

1717

1818
if __name__ == "__main__":

0 commit comments

Comments
 (0)