Skip to content

Commit d32e5f2

Browse files
committed
Update CDP Mode examples
1 parent 3772ff0 commit d32e5f2

4 files changed

Lines changed: 47 additions & 0 deletions

File tree

examples/cdp_mode/raw_amazon.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from seleniumbase import SB
2+
3+
with SB(uc=True, test=True, ad_block=True) as sb:
4+
url = "https://www.amazon.com"
5+
sb.activate_cdp_mode(url)
6+
sb.sleep(2)
7+
sb.click_if_visible('button[alt="Continue shopping"]')
8+
sb.sleep(2)
9+
sb.press_keys('input[role="searchbox"]', "TI-89\n")
10+
sb.sleep(3)
11+
print(sb.get_page_title())
12+
sb.save_as_pdf_to_logs()
13+
sb.save_page_source_to_logs()
14+
sb.save_screenshot_to_logs()
15+
print("Logs have been saved to: ./latest_logs/")

examples/cdp_mode/raw_facebook.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from seleniumbase import SB
2+
3+
with SB(uc=True, test=True, ad_block=True) as sb:
4+
url = "https://www.facebook.com/SeleniumBase"
5+
sb.activate_cdp_mode(url)
6+
sb.sleep(1)
7+
sb.click_if_visible('[aria-label="Close"] i')
8+
sb.sleep(1)
9+
for i in range(14):
10+
sb.cdp.scroll_down(15)
11+
print(sb.get_page_title())
12+
sb.save_as_pdf_to_logs()
13+
sb.save_page_source_to_logs()
14+
sb.save_screenshot_to_logs()
15+
print("Logs have been saved to: ./latest_logs/")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import mycdp
2+
from seleniumbase import SB
3+
4+
with SB(uc=True, test=True) as sb:
5+
sb.activate_cdp_mode("https://learn.microsoft.com/en-us/")
6+
tab = sb.cdp.get_active_tab()
7+
loop = sb.cdp.get_event_loop()
8+
print(loop.run_until_complete(tab.send(mycdp.storage.get_cookies())))
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""Test connecting to an existing browser."""
2+
from seleniumbase import sb_cdp
3+
4+
sb1 = sb_cdp.Chrome("https://example.com")
5+
port = sb1.get_rd_port()
6+
sb2 = sb_cdp.Chrome(host="127.0.0.1", port=port)
7+
print("The remote-debugging port: %s" % port)
8+
assert sb1.get_rd_port() == sb2.get_rd_port()
9+
assert sb1.get_current_url() == sb2.get_current_url()

0 commit comments

Comments
 (0)