|
32 | 32 | <li><a href="#sb_sf_21"><strong>21. SeleniumBase SB (Python context manager)</strong></a></li> |
33 | 33 | <li><a href="#sb_sf_22"><strong>22. The driver manager (via context manager)</strong></a></li> |
34 | 34 | <li><a href="#sb_sf_23"><strong>23. The driver manager (via direct import)</strong></a></li> |
35 | | -<li><a href="#sb_sf_24"><strong>24. CDP driver (async/await API. No Selenium)</strong></a></li> |
36 | | -<li><a href="#sb_sf_25"><strong>25. CDP driver (SB CDP Sync API. No Selenium)</strong></a></li> |
| 35 | +<li><a href="#sb_sf_24"><strong>24. Pure CDP Mode (Async API. No Selenium)</strong></a></li> |
| 36 | +<li><a href="#sb_sf_25"><strong>25. Pure CDP Mode (Sync API. No Selenium)</strong></a></li> |
37 | 37 | </ul> |
38 | 38 | </blockquote> |
39 | 39 |
|
@@ -1020,9 +1020,9 @@ The ``Driver()`` manager format can be used as a drop-in replacement for virtual |
1020 | 1020 | When using the ``Driver()`` format, you may need to activate a Virtual Display on your own if you want to run headed tests in a headless Linux environment. (See https://github.com/mdmintz/sbVirtualDisplay for details.) One such example of this is using an authenticated proxy, which is configured via a Chrome extension that is generated at runtime. (Note that regular headless mode in Chrome doesn't support extensions.) |
1021 | 1021 |
|
1022 | 1022 | <a id="sb_sf_24"></a> |
1023 | | -<h2><img src="https://seleniumbase.github.io/img/logo3b.png" title="SeleniumBase" width="32" /> 24. CDP driver (async/await API. No Selenium)</h2> |
| 1023 | +<h2><img src="https://seleniumbase.github.io/img/logo3b.png" title="SeleniumBase" width="32" /> 24. Pure CDP Mode (Async API. No Selenium)</h2> |
1024 | 1024 |
|
1025 | | -This format provides a pure CDP way of using SeleniumBase (without Selenium or a test runner). The async/await API is used. Here's an example: |
| 1025 | +This format provides a pure CDP way of using SeleniumBase (without Selenium/WebDriver or a test runner). The <code>async</code>/<code>await</code> API is used. Here's an example: |
1026 | 1026 |
|
1027 | 1027 | ```python |
1028 | 1028 | import asyncio |
@@ -1053,9 +1053,33 @@ if __name__ == "__main__": |
1053 | 1053 | (See <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/raw_basic_async.py">examples/cdp_mode/raw_basic_async.py</a> for the test.) |
1054 | 1054 |
|
1055 | 1055 | <a id="sb_sf_25"></a> |
1056 | | -<h2><img src="https://seleniumbase.github.io/img/logo3b.png" title="SeleniumBase" width="32" /> 25. CDP driver (SB CDP Sync API. No Selenium)</h2> |
| 1056 | +<h2><img src="https://seleniumbase.github.io/img/logo3b.png" title="SeleniumBase" width="32" /> 25. Pure CDP Mode (Sync API. No Selenium)</h2> |
1057 | 1057 |
|
1058 | | -This format provides a pure CDP way of using SeleniumBase (without Selenium/WebDriver or a test runner). The expanded SB CDP Sync API is used. Here's an example: |
| 1058 | +This format provides a pure CDP way of using SeleniumBase (without Selenium/WebDriver or a test runner). The expanded <code>sb_cdp</code> Sync API is used. Here's an example: |
| 1059 | + |
| 1060 | +```python |
| 1061 | +from seleniumbase import sb_cdp |
| 1062 | + |
| 1063 | +url = "https://seleniumbase.io/simple/login" |
| 1064 | +sb = sb_cdp.Chrome(url) |
| 1065 | +sb.type("#username", "demo_user") |
| 1066 | +sb.type("#password", "secret_pass") |
| 1067 | +sb.click('a:contains("Sign in")') |
| 1068 | +sb.assert_exact_text("Welcome!", "h1") |
| 1069 | +sb.assert_element("img#image1") |
| 1070 | +sb.highlight("#image1") |
| 1071 | +top_nav = sb.find_element("div.topnav") |
| 1072 | +links = top_nav.query_selector_all("a") |
| 1073 | +for nav_item in links: |
| 1074 | + print(nav_item.text) |
| 1075 | +sb.click_link("Sign out") |
| 1076 | +sb.assert_text("signed out", "#top_message") |
| 1077 | +sb.driver.stop() |
| 1078 | +``` |
| 1079 | + |
| 1080 | +(See <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/raw_basic_cdp.py">examples/cdp_mode/raw_basic_cdp.py</a> for the test.) |
| 1081 | + |
| 1082 | +Here's a Pure CDP Mode example that bypasses bot-detection to scrape data from a website: |
1059 | 1083 |
|
1060 | 1084 | ```python |
1061 | 1085 | from seleniumbase import sb_cdp |
|
0 commit comments