-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery_demo.py
More file actions
45 lines (32 loc) · 1.3 KB
/
query_demo.py
File metadata and controls
45 lines (32 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""
Day 4 Example: Query engine demonstration
"""
from sentience import SentienceBrowser, snapshot, query, find
def main():
with SentienceBrowser(headless=False) as browser:
# Navigate to a page with links
browser.page.goto("https://example.com")
browser.page.wait_for_load_state("networkidle")
snap = snapshot(browser)
# Query examples
print("=== Query Examples ===\n")
# Find all buttons
buttons = query(snap, "role=button")
print(f"Found {len(buttons)} buttons")
# Find all links
links = query(snap, "role=link")
print(f"Found {len(links)} links")
# Find clickable elements
clickables = query(snap, "clickable=true")
print(f"Found {len(clickables)} clickable elements")
# Find element with text containing "More"
more_link = find(snap, "text~'More'")
if more_link:
print(f"\nFound 'More' link: {more_link.text} (id: {more_link.id})")
else:
print("\nNo 'More' link found")
# Complex query: clickable links
clickable_links = query(snap, "role=link clickable=true")
print(f"\nFound {len(clickable_links)} clickable links")
if __name__ == "__main__":
main()