assert_locator_node to branch your automation based on whether a specific element is present on the page. It evaluates a Playwright locator within a timeout and executes if_nodes if the assertion passes, or else_nodes if it does not.
This is the lowest-overhead way to handle optional elements—no LLM call, no extraction variable, just a direct visibility check.
Structure
Properties
| Property | Type | Default | Description |
|---|---|---|---|
type | "assert_locator_node" | Required | Node discriminator |
locator | str | Required | Playwright locator command (page.<locator> style) |
assertion | "to_be_visible" | "to_be_hidden" | Required | Condition to test |
timeout | float | 5.0 | Seconds to wait for the assertion before treating it as failed |
if_nodes | list[node] | [] | Nodes to run when the assertion passes |
else_nodes | list[node] | [] | Nodes to run when the assertion fails (times out) |
if_nodes and else_nodes accept any node type: action_node, if_else_node, for_loop_node, or nested assert_locator_node.
Assertions
| Assertion | Passes when |
|---|---|
to_be_visible | The element exists in the DOM and is visible within timeout seconds |
to_be_hidden | The element is absent or hidden within timeout seconds |
timeout, else_nodes run (no error is raised).
Examples
Skip a step when an element is absent
Check whether a “Cookie Consent” banner is visible before trying to dismiss it:Assert an element is hidden before proceeding
Wait up to 10 seconds for a loading spinner to disappear:Variable substitution in the locator
locator supports {variable[index]} substitution, so you can target elements dynamically:
assert_locator_node vs if_else_node
assert_locator_node | if_else_node | |
|---|---|---|
| Condition | Playwright locator visibility | Python expression on a variable |
| Requires extraction? | No | Yes — needs an extraction_action with output_variable_names first |
| Cost | Zero (no LLM) | Zero (expression eval) + cost of extraction |
| Best for | Element present/absent checks | Comparing extracted values, complex logic |
assert_locator_node when you only need to know if something is on the page. Use if_else_node when you need to compare the content of what was extracted.
Locator Syntax
Thelocator field uses the same Playwright command syntax as interaction actions—omit the leading page.: