Skip to content

Commit 21057ef

Browse files
committed
updated readme
1 parent 28eeb97 commit 21057ef

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

README.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ first_row = query(snap, "bbox.y<600")
144144

145145
### Actions - Interact with Elements
146146
- **`click(browser, element_id)`** - Click element by ID
147+
- **`click_rect(browser, rect)`** - Click at center of rectangle (coordinate-based)
147148
- **`type_text(browser, element_id, text)`** - Type into input fields
148149
- **`press(browser, key)`** - Press keyboard keys (Enter, Escape, Tab, etc.)
149150

@@ -158,17 +159,53 @@ print(f"Duration: {result.duration_ms}ms")
158159
print(f"URL changed: {result.url_changed}")
159160
```
160161

162+
**Coordinate-based clicking:**
163+
```python
164+
from sentience import click_rect
165+
166+
# Click at center of rectangle (x, y, width, height)
167+
click_rect(browser, {"x": 100, "y": 200, "w": 50, "h": 30})
168+
169+
# With visual highlight (default: red border for 2 seconds)
170+
click_rect(browser, {"x": 100, "y": 200, "w": 50, "h": 30}, highlight=True, highlight_duration=2.0)
171+
172+
# Using element's bounding box
173+
snap = snapshot(browser)
174+
element = find(snap, "role=button")
175+
if element:
176+
click_rect(browser, {
177+
"x": element.bbox.x,
178+
"y": element.bbox.y,
179+
"w": element.bbox.width,
180+
"h": element.bbox.height
181+
})
182+
```
183+
161184
### Wait & Assertions
162-
- **`wait_for(browser, selector, timeout=5.0)`** - Wait for element to appear
185+
- **`wait_for(browser, selector, timeout=5.0, interval=None, use_api=None)`** - Wait for element to appear
163186
- **`expect(browser, selector)`** - Assertion helper with fluent API
164187

165188
**Examples:**
166189
```python
167-
# Wait for element
190+
# Wait for element (auto-detects optimal interval based on API usage)
168191
result = wait_for(browser, "role=button text='Submit'", timeout=10.0)
169192
if result.found:
170193
print(f"Found after {result.duration_ms}ms")
171194

195+
# Use local extension with fast polling (0.25s interval)
196+
result = wait_for(browser, "role=button", timeout=5.0, use_api=False)
197+
198+
# Use remote API with network-friendly polling (1.5s interval)
199+
result = wait_for(browser, "role=button", timeout=5.0, use_api=True)
200+
201+
# Custom interval override
202+
result = wait_for(browser, "role=button", timeout=5.0, interval=0.5, use_api=False)
203+
204+
# Semantic wait conditions
205+
wait_for(browser, "clickable=true", timeout=5.0) # Wait for clickable element
206+
wait_for(browser, "importance>100", timeout=5.0) # Wait for important element
207+
wait_for(browser, "role=link visible=true", timeout=5.0) # Wait for visible link
208+
172209
# Assertions
173210
expect(browser, "role=button text='Submit'").to_exist(timeout=5.0)
174211
expect(browser, "role=heading").to_be_visible()

0 commit comments

Comments
 (0)