Synchronization¶
Methods for waiting for elements to appear, disappear, or checking existence.
element_exists¶
Checks whether an element exists on the page.
Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
selector |
str |
-- | CSS selector or XPath |
timeout |
float |
0 |
If > 0, waits up to N seconds |
Examples¶
# Instant check
if await browser.element_exists("#success-modal"):
print("Success!")
# Wait up to 5 seconds
if await browser.element_exists("#result", timeout=5):
text = await browser.get_text("#result")
wait_element¶
Waits for an element to meet a condition. Raises an error on timeout.
Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
selector |
str |
-- | CSS selector or XPath |
condition |
str |
"visible" |
"visible", "clickable", "present" |
timeout |
float |
config | Timeout in seconds |
Example¶
await browser.wait_element("#loading", condition="visible", timeout=10)
await browser.click("#loading")
Exception¶
Raises ElementTimeoutError if the condition is not met within the timeout.
wait_element_vanish¶
Waits for an element to disappear from the page.
Example¶
await browser.click("#btn-save")
await browser.wait_element_vanish("#spinner", timeout=15)
print("Saved successfully!")
Exception¶
Raises ElementTimeoutError if the element still exists after the timeout.
find_element¶
Finds an element and returns information about it.
Return¶
{
"tag": "button",
"id": "btn-login",
"classes": ["btn", "btn-primary"],
"text": "Sign In",
"visible": True,
}