Skip to content

Commit 68a5156

Browse files
committed
Add a new CDP Mode example
1 parent 8decf8d commit 68a5156

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

examples/cdp_mode/raw_demo_site.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
"""Example of using various CDP Mode commands"""
2+
from seleniumbase import SB
3+
4+
with SB(uc=True, test=True) as sb:
5+
url = "https://seleniumbase.io/demo_page"
6+
sb.activate_cdp_mode(url)
7+
8+
# Assert various things
9+
sb.cdp.assert_title("Web Testing Page")
10+
sb.cdp.assert_element("tbody#tbodyId")
11+
sb.cdp.assert_text("Demo Page", "h1")
12+
13+
# Type text into various text fields and then assert
14+
sb.cdp.type("#myTextInput", "This is Automated")
15+
sb.cdp.type("textarea.area1", "Testing Time!\n")
16+
sb.cdp.type('[name="preText2"]', "Typing Text!")
17+
sb.cdp.assert_text("This is Automated", "#myTextInput")
18+
sb.cdp.assert_text("Testing Time!\n", "textarea.area1")
19+
sb.cdp.assert_text("Typing Text!", '[name="preText2"]')
20+
21+
# Hover & click a dropdown element and assert results
22+
sb.cdp.assert_text("Automation Practice", "h3")
23+
sb.cdp.gui_hover_and_click("#myDropdown", "#dropOption2")
24+
sb.cdp.assert_text("Link Two Selected", "h3")
25+
26+
# Click a button and then verify the expected results
27+
sb.cdp.assert_text("This Text is Green", "#pText")
28+
sb.cdp.click('button:contains("Click Me")')
29+
sb.cdp.assert_text("This Text is Purple", "#pText")
30+
31+
# Verify that a slider control updates a progress bar
32+
sb.cdp.assert_element('progress[value="50"]')
33+
sb.cdp.set_value("input#mySlider", "100")
34+
sb.cdp.assert_element('progress[value="100"]')
35+
36+
# Verify that a "select" option updates a meter bar
37+
sb.cdp.assert_element('meter[value="0.25"]')
38+
sb.cdp.select_option_by_text("#mySelect", "Set to 75%")
39+
sb.cdp.assert_element('meter[value="0.75"]')
40+
41+
# Verify that clicking a radio button selects it
42+
sb.cdp.assert_false(sb.cdp.is_selected("#radioButton2"))
43+
sb.cdp.click("#radioButton2")
44+
sb.cdp.assert_true(sb.cdp.is_selected("#radioButton2"))
45+
46+
# Verify that clicking a checkbox makes it selected
47+
sb.cdp.assert_element_not_visible("img#logo")
48+
sb.cdp.assert_false(sb.cdp.is_selected("#checkBox1"))
49+
sb.cdp.click("#checkBox1")
50+
sb.cdp.assert_true(sb.cdp.is_selected("#checkBox1"))
51+
sb.cdp.assert_element("img#logo")
52+
53+
# Verify clicking on multiple elements with one call
54+
sb.cdp.assert_false(sb.cdp.is_selected("#checkBox2"))
55+
sb.cdp.assert_false(sb.cdp.is_selected("#checkBox3"))
56+
sb.cdp.assert_false(sb.cdp.is_selected("#checkBox4"))
57+
sb.cdp.click_visible_elements("input.checkBoxClassB")
58+
sb.cdp.assert_true(sb.cdp.is_selected("#checkBox2"))
59+
sb.cdp.assert_true(sb.cdp.is_selected("#checkBox3"))
60+
sb.cdp.assert_true(sb.cdp.is_selected("#checkBox4"))
61+
62+
# Verify Drag and Drop
63+
sb.cdp.assert_element_not_visible("div#drop2 img#logo")
64+
sb.cdp.gui_drag_and_drop("img#logo", "div#drop2")
65+
sb.cdp.assert_element("div#drop2 img#logo")
66+
67+
# Click inside an iframe and test highlighting
68+
sb.cdp.flash("iframe#myFrame3")
69+
sb.cdp.sleep(1)
70+
sb.cdp.nested_click("iframe#myFrame3", ".fBox")
71+
sb.cdp.sleep(0.5)
72+
sb.cdp.highlight("iframe#myFrame3")

0 commit comments

Comments
 (0)