Skip to content

Commit 4732aaf

Browse files
authored
Merge pull request #4365 from seleniumbase/cdp-mode-patch-111
CDP Mode: Patch 111 (and more)
2 parents cba1d35 + 583e6cd commit 4732aaf

50 files changed

Lines changed: 246 additions & 482 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,10 +507,10 @@ pip install -e .
507507
<summary> ▶️ Here's sample output from a chromedriver download. (<b>click to expand</b>)</summary>
508508
509509
```zsh
510-
*** chromedriver to download = 148.0.7778.178 (Latest Stable)
510+
*** chromedriver to download = 149.0.7827.54 (Latest Stable)
511511
512512
Downloading chromedriver-mac-arm64.zip from:
513-
https://storage.googleapis.com/chrome-for-testing-public/148.0.7778.178/mac-arm64/chromedriver-mac-arm64.zip ...
513+
https://storage.googleapis.com/chrome-for-testing-public/149.0.7827.54/mac-arm64/chromedriver-mac-arm64.zip ...
514514
Download Complete!
515515
516516
Extracting ['chromedriver'] from chromedriver-mac-arm64.zip ...
@@ -520,8 +520,8 @@ The file [chromedriver] was saved to:
520520
~/github/SeleniumBase/seleniumbase/drivers/
521521
chromedriver
522522
523-
Making [chromedriver 148.0.7778.178] executable ...
524-
[chromedriver 148.0.7778.178] is now ready for use!
523+
Making [chromedriver 149.0.7827.54] executable ...
524+
[chromedriver 149.0.7827.54] is now ready for use!
525525
```
526526
527527
</details>
@@ -853,7 +853,6 @@ pytest test_coffee_cart.py --trace
853853
--screenshot # (Save a screenshot at the end of each test.)
854854
--no-screenshot # (No screenshots saved unless tests directly ask it.)
855855
--visual-baseline # (Set the visual baseline for Visual/Layout tests.)
856-
--wire # (Use selenium-wire's webdriver for replacing selenium webdriver.)
857856
--external-pdf # (Set Chromium "plugins.always_open_pdf_externally":True.)
858857
--timeout-multiplier=MULTIPLIER # (Multiplies the default timeout values.)
859858
--list-fail-page # (After each failing test, list the URL of the failure.)

examples/ReadMe.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@
44

55
<p align="left"><a align="center" href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_demo_site.py"><img align="center" src="https://seleniumbase.github.io/cdn/img/sb_demo_page.png" alt="SeleniumBase Demo Page" width="420" /></a></p>
66

7-
* <b>SeleniumBase</b> "tests" are run with <b>pytest</b>.
7+
* Many <b>SeleniumBase</b> "tests" run with <b><code>pytest</code></b>.
88
* Chrome is the default browser if not specified.
9-
* Tests are structured using [25 unique syntax formats](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md).
9+
* Tests are structured using [25 unique design patterns](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md).
1010
* Logs from test failures are saved to `./latest_logs/`.
1111
* Tests can be run with [multiple command-line options](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/customizing_test_runs.md).
1212
* Examples can be found in [SeleniumBase/examples/](https://github.com/seleniumbase/SeleniumBase/tree/master/examples).
13-
* For stealthy examples, see [SeleniumBase/examples/cdp_mode/](https://github.com/seleniumbase/SeleniumBase/tree/master/examples/cdp_mode).
13+
* Stealthy CDP Mode examples: [SeleniumBase/examples/cdp_mode/](https://github.com/seleniumbase/SeleniumBase/tree/master/examples/cdp_mode).
14+
* Stealthy Playwright examples: [./examples/cdp_mode/playwright/](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/playwright/ReadMe.md).
1415

1516
(NOTE: Some example tests fail on purpose to demonstrate [logging features](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/example_logs/ReadMe.md).)
1617

1718
--------
1819

19-
<h3><img src="https://seleniumbase.github.io/img/logo7.png" title="SeleniumBase" width="32" /> Example tests with run commands to help you get started:</h3>
20-
21-
--------
20+
<h3><img src="https://seleniumbase.github.io/img/logo7.png" title="SeleniumBase" width="32" /> Example tests with run commands:</h3>
2221

2322
Run an [example test](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/my_first_test.py): (Default option: `--chrome`)
2423

examples/cdp_mode/ReadMe.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ with SB(uc=True, test=True, ad_block=True) as sb:
323323
price_text = price_text.split("current price ")[-1]
324324
price_text = price_text.split(" ")[0]
325325
print(" (" + price_text + ")")
326+
item.scroll_into_view()
326327
```
327328

328329
</details>
@@ -662,8 +663,7 @@ await tab.set_window_size(left=0, top=0, width=1280, height=1024)
662663
await tab.set_window_rect(left=0, top=0, width=1280, height=1024)
663664
await tab.activate()
664665
await tab.bring_to_front()
665-
await tab.set_window_state(
666-
left=0, top=0, width=1280, height=720, state="normal")
666+
await tab.set_window_state(left=0, top=0, width=1280, height=720, state="normal")
667667
await tab.get_navigation_history()
668668
await tab.get_user_agent()
669669
await tab.get_cookie_string()
@@ -677,8 +677,7 @@ await tab.wait_for(selector="", text="", timeout=10)
677677
await tab.set_attributes(selector, attribute, value)
678678
await tab.internalize_links()
679679
await tab.download_file(url, filename=None)
680-
await tab.save_screenshot(
681-
filename="auto", format="png", full_page=False)
680+
await tab.save_screenshot(filename="auto", format="png", full_page=False)
682681
await tab.print_to_pdf(filename="auto")
683682
await tab.set_download_path(path)
684683
await tab.get_all_linked_sources()

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:

0 commit comments

Comments
 (0)