Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/console_scripts/ReadMe.md">🌠 Scripts</a> |
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/mobile_testing.md">📱 Mobile</a>
<br />
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/method_summary.md">📘 APIs</a> |
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md"> 🔠 Formats</a> |
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/method_summary.md">📘 API</a> |
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md"> 🔠 Syntaxes</a> |
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/recorder_mode.md">🔴 Recorder</a> |
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/example_logs/ReadMe.md">📊 Dashboard</a> |
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/locale_codes.md">🗾 Locales</a> |
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/locale_codes.md">🗾 Locale</a> |
<a href="https://seleniumbase.io/devices/?url=seleniumbase.com">💻 Farm</a>
<br />
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/commander.md">🎖️ GUI</a> |
Expand All @@ -39,18 +39,17 @@
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/utilities/selenium_grid/ReadMe.md">🌐 Grid</a>
<br />
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/how_it_works.md">👁️ How</a> |
<a href="https://github.com/seleniumbase/SeleniumBase/tree/master/examples/migration/raw_selenium">🚝 Migrate</a> |
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/case_plans.md">🗂️ CasePlans</a> |
<a href="https://github.com/seleniumbase/SeleniumBase/tree/master/examples/boilerplates">♻️ Template</a> |
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/master_qa/ReadMe.md">🧬 Hybrid</a> |
<a href="https://github.com/seleniumbase/SeleniumBase/tree/master/examples/migration/raw_selenium">🚝 Migration</a> |
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/playwright/ReadMe.md">🎭 Stealthy Playwright</a> |
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/master_qa/ReadMe.md">🛂 MasterQA</a> |
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/tour_examples/ReadMe.md">🚎 Tours</a>
<br />
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/integrations/github/workflows/ReadMe.md">🤖 CI/CD</a> |
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/js_package_manager.md">🕹️ JSMgr</a> |
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/translations.md">🌏 Translator</a> |
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/presenter/ReadMe.md">🎞️ Presenter</a> |
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/dialog_boxes/ReadMe.md">🛂 Dialog</a> |
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/visual_testing/ReadMe.md">🖼️ Visual</a>
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/visual_testing/ReadMe.md">🖼️ Visual</a> |
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/case_plans.md">🗂️ CPlans</a>
<br />
</p>

Expand Down
126 changes: 70 additions & 56 deletions examples/cdp_mode/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -620,63 +620,77 @@ sb.driver.stop()

### 🐙 <b translate="no">CDP Mode</b> Async API / Methods

Initialization:

```python
from seleniumbase import cdp_driver

driver = await cdp_driver.start_async()
tab = await driver.get(url, **kwargs)
```

Methods: (Sometimes `tab` is named `page` in examples)

```python
await get(url="about:blank")
await open(url="about:blank")
await find(text, best_match=False, timeout=10) # `text` can be a selector
await find_all(text, timeout=10) # `text` can be a selector
await select(selector, timeout=10)
await select_all(selector, timeout=10, include_frames=False)
await query_selector(selector)
await query_selector_all(selector)
await find_element_by_text(text, best_match=False)
await find_elements_by_text(text)
await reload(ignore_cache=True, script_to_evaluate_on_load=None)
await evaluate(expression)
await js_dumps(obj_name)
await back()
await forward()
await get_window()
await get_content()
await maximize()
await minimize()
await fullscreen()
await medimize()
await set_window_size(left=0, top=0, width=1280, height=1024)
await set_window_rect(left=0, top=0, width=1280, height=1024)
await activate()
await bring_to_front()
await set_window_state(left=0, top=0, width=1280, height=720, state="normal")
await get_navigation_history()
await open_external_inspector() # Open a separate browser for debugging
await close()
await scroll_down(amount=25)
await scroll_up(amount=25)
await wait_for(selector="", text="", timeout=10)
await download_file(url, filename=None)
await save_screenshot(filename="auto", format="png", full_page=False)
await print_to_pdf(filename="auto")
await set_download_path(path)
await get_all_linked_sources()
await get_all_urls(absolute=True)
await get_html()
await get_page_source()
await is_element_present(selector)
await is_element_visible(selector)
await get_element_rect(selector, timeout=5) # (relative to window)
await get_window_rect()
await get_gui_element_rect(selector, timeout=5) # (relative to screen)
await get_title()
await send_keys(selector, text, timeout=5)
await type(selector, text, timeout=5)
await click(selector, timeout=5)
await click_with_offset(selector, x, y, center=False, timeout=5)
await solve_captcha()
await click_captcha() # Same as solve_captcha()
await get_document()
await get_flattened_document()
await get_local_storage()
await set_local_storage(items)
await tab.get(url="about:blank")
await tab.open(url="about:blank")
await tab.find(text, best_match=False, timeout=10) # text can be selector
await tab.find_all(text, timeout=10) # text can be selector
await tab.select(selector, timeout=10)
await tab.select_all(selector, timeout=10, include_frames=False)
await tab.query_selector(selector)
await tab.query_selector_all(selector)
await tab.find_element_by_text(text, best_match=False)
await tab.find_elements_by_text(text)
await tab.reload(ignore_cache=True, script_to_evaluate_on_load=None)
await tab.evaluate(expression)
await tab.js_dumps(obj_name)
await tab.back()
await tab.forward()
await tab.get_window()
await tab.get_content()
await tab.maximize()
await tab.minimize()
await tab.fullscreen()
await tab.medimize()
await tab.set_window_size(left=0, top=0, width=1280, height=1024)
await tab.set_window_rect(left=0, top=0, width=1280, height=1024)
await tab.activate()
await tab.bring_to_front()
await tab.set_window_state(
left=0, top=0, width=1280, height=720, state="normal")
await tab.get_navigation_history()
await tab.open_external_inspector() # Open separate browser for debugging
await tab.close()
await tab.scroll_down(amount=25)
await tab.scroll_up(amount=25)
await tab.wait_for(selector="", text="", timeout=10)
await tab.download_file(url, filename=None)
await tab.save_screenshot(
filename="auto", format="png", full_page=False)
await tab.print_to_pdf(filename="auto")
await tab.set_download_path(path)
await tab.get_all_linked_sources()
await tab.get_all_urls(absolute=True)
await tab.get_html()
await tab.get_page_source()
await tab.is_element_present(selector)
await tab.is_element_visible(selector)
await tab.get_element_rect(selector, timeout=5) # (window-based)
await tab.get_window_rect()
await tab.get_gui_element_rect(selector, timeout=5) # (screen-based)
await tab.get_title()
await tab.get_current_url()
await tab.send_keys(selector, text, timeout=5)
await tab.type(selector, text, timeout=5)
await tab.click(selector, timeout=5)
await tab.click_with_offset(selector, x, y, center=False, timeout=5)
await tab.solve_captcha()
await tab.click_captcha() # Same as solve_captcha()
await tab.get_document()
await tab.get_flattened_document()
await tab.get_local_storage()
await tab.set_local_storage(items)
```

--------
Expand Down
23 changes: 12 additions & 11 deletions examples/cdp_mode/raw_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,27 @@

async def main():
url = "seleniumbase.io/simple/login"
driver = await cdp_driver.start_async(incognito=True)
page = await driver.get(url)
print(await page.evaluate("document.title"))
element = await page.select("#username")
await element.send_keys_async("demo_user")
element = await page.select("#password")
await element.send_keys_async("secret_pass")
element = await page.select("#log-in")
await element.click_async()
time.sleep(1)
driver = await cdp_driver.start_async()
page = await driver.get(url, lang="en")
print(await page.get_title())
await page.type("#username", "demo_user")
await page.type("#password", "secret_pass")
await page.click("#log-in")
print(await page.get_title())
element = await page.select("h1")
assert element.text == "Welcome!"
top_nav = await page.select("div.topnav")
links = await top_nav.query_selector_all_async("a")
for nav_item in links:
print(nav_item.text)
driver.stop()

if __name__ == "__main__":
# Call an async function with awaited methods
loop = asyncio.new_event_loop()
loop.run_until_complete(main())

# Call everything without using async / await
# An example of wrapping all async calls with event loops
driver = cdp_driver.start_sync()
page = loop.run_until_complete(driver.get("about:blank"))
loop.run_until_complete(page.set_locale("en"))
Expand Down
1 change: 1 addition & 0 deletions examples/cdp_mode/raw_basic_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ async def main():
links = await top_nav.query_selector_all_async("a")
for nav_item in links:
print(nav_item.text)
driver.stop()

if __name__ == "__main__":
# Call an async function with awaited methods
Expand Down
9 changes: 3 additions & 6 deletions examples/cdp_mode/raw_cookies_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ async def get_login_cookies():
url = "https://www.saucedemo.com"
driver = await cdp_driver.start_async(incognito=True)
page = await driver.get(url)
element = await page.select("#user-name")
await element.send_keys_async("standard_user")
element = await page.select("#password")
await element.send_keys_async("secret_sauce")
element = await page.select('input[type="submit"]')
await element.click_async()
await page.type("#user-name", "standard_user")
await page.type("#password", "secret_sauce")
await page.click('input[type="submit"]')
cookies = await driver.cookies.get_all()
driver.stop()
return cookies
Expand Down
7 changes: 2 additions & 5 deletions examples/cdp_mode/raw_mobile_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@ async def main():
)
page = await driver.get(url, lang="en")
time.sleep(3)
try:
element = await page.select('[style*="grid"] div div', timeout=1)
await element.mouse_click_with_offset_async(32, 28)
except Exception:
pass # Maybe CAPTCHA was already bypassed
await page.solve_captcha()
element = await page.select('label[for="user_login"]')
await element.flash_async(duration=1.5, color="44EE44")
time.sleep(1)
element = await page.select('[data-testid="sign-in-button"]')
await element.flash_async(duration=2, color="44EE44")
time.sleep(2)
driver.stop()

if __name__ == "__main__":
# Call an async function with awaited methods
Expand Down
6 changes: 2 additions & 4 deletions examples/cdp_mode/raw_multi_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ async def main(url):
page = await driver.get(url)
await page.set_window_rect(randint(4, 600), randint(8, 410), 860, 500)
await page.sleep(0.5)
field = await page.select("input")
await field.send_keys_async("Text")
button = await page.select("button")
await button.click_async()
await page.type("input", "Text")
await page.click("button")
await page.sleep(2)
driver.stop()

Expand Down
2 changes: 2 additions & 0 deletions help_docs/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
<a href="https://seleniumbase.io/help_docs/recorder_mode/">🔴 Recorder</a> |
<a href="https://seleniumbase.io/devices/?url=seleniumbase.io">💻 Device Farm</a>
<br />
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/cdp_mode/playwright/ReadMe.md">🎭 Stealthy Playwright Mode</a>
<br />
<a href="https://seleniumbase.io/examples/presenter/ReadMe/">🎞️ Slides</a> |
<a href="https://seleniumbase.io/examples/chart_maker/ReadMe/">📶 Chart Maker</a>
<br / >
Expand Down
Loading