> ## Documentation Index
> Fetch the complete documentation index at: https://docs.optexity.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Assert Locator Node

> Check Playwright locator visibility and store the result as a boolean variable

Use `assert_locator_node` to check whether a specific element is present on the page and store the result. It evaluates a Playwright locator within a timeout and writes a boolean into `output_variable_name` (`true` if the assertion passes, `false` if it does not). You then branch on that variable with an [`if_else_node`](/docs/building-automations/if-else-node).

This is the lowest-overhead way to capture element presence—no LLM call, no extraction step, just a direct visibility check that becomes a reusable variable.

## Structure

```json theme={null}
{
  "type": "assert_locator_node",
  "locator": "get_by_role(\"alert\", name=\"Error\")",
  "assertion": "to_be_visible",
  "output_variable_name": "error_visible",
  "timeout": 5.0
}
```

The node above stores `error_visible = [true]` or `error_visible = [false]`. Reference it later as `{error_visible[0]}`.

## 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                                                              |
| `output_variable_name` | `str`                               | Required | Variable to store the boolean result, as a single-element list (e.g. `[true]`) |
| `timeout`              | `float`                             | `5.0`    | Seconds to wait for the assertion before treating it as failed                 |

The result is stored as a single-element list, matching the convention used by other variables, so you reference it with index `[0]` (e.g. `{error_visible[0]}`).

## Assertions

| Assertion       | Result is `true` 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              |

If the assertion does not pass within `timeout`, the variable is set to `false` (no error is raised). If the locator does not resolve at all, the result is also `false`.

## Examples

### Dismiss an element only when it appears

Check whether an error alert is visible, then dismiss it with a following `if_else_node`:

```json theme={null}
[
  {
    "type": "assert_locator_node",
    "locator": "get_by_role(\"alert\", name=\"Error\")",
    "assertion": "to_be_visible",
    "output_variable_name": "error_visible",
    "timeout": 5.0
  },
  {
    "type": "if_else_node",
    "condition": "{error_visible[0]}",
    "if_nodes": [
      {
        "type": "action_node",
        "interaction_action": {
          "click_element": {
            "command": "get_by_role(\"button\", name=\"Dismiss\")"
          }
        }
      }
    ],
    "else_nodes": []
  }
]
```

### Wait for a spinner to disappear, then branch

Wait up to 10 seconds for a loading spinner to be hidden, then submit or fail:

```json theme={null}
[
  {
    "type": "assert_locator_node",
    "locator": "get_by_test_id(\"loading-spinner\")",
    "assertion": "to_be_hidden",
    "output_variable_name": "spinner_gone",
    "timeout": 10.0
  },
  {
    "type": "if_else_node",
    "condition": "{spinner_gone[0]}",
    "if_nodes": [
      {
        "type": "action_node",
        "interaction_action": {
          "click_element": {
            "command": "get_by_role(\"button\", name=\"Submit\")"
          }
        }
      }
    ],
    "else_nodes": [
      {
        "type": "action_node",
        "misc_action": {
          "fail_state": {
            "message": "Loading spinner did not disappear within 10 seconds"
          }
        }
      }
    ]
  }
]
```

### Variable substitution in the locator

`locator` supports `{variable[index]}` substitution, so you can target elements dynamically:

```json theme={null}
{
  "type": "assert_locator_node",
  "locator": "get_by_text(\"{order_id[0]}\")",
  "assertion": "to_be_visible",
  "output_variable_name": "order_found",
  "timeout": 5.0
}
```

## assert\_locator\_node vs if\_else\_node

|                          | `assert_locator_node`                             | `if_else_node`                                                                                  |
| ------------------------ | ------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| **Role**                 | Captures element visibility as a boolean variable | Branches on a Python expression over a variable                                                 |
| **Condition**            | Playwright locator visibility                     | Python expression on a variable                                                                 |
| **Requires extraction?** | No                                                | Yes — needs a variable to branch on (e.g. from `assert_locator_node` or an `extraction_action`) |
| **Cost**                 | Zero (no LLM)                                     | Zero (expression eval)                                                                          |
| **Best for**             | Element present/absent checks                     | Acting on a captured boolean or comparing extracted values                                      |

`assert_locator_node` produces the boolean; `if_else_node` consumes it. Pair them to run steps conditionally on element presence, or use the variable in any later condition.

## Locator Syntax

The `locator` field uses the same Playwright command syntax as interaction actions—omit the leading `page.`:

```json theme={null}
{ "locator": "get_by_role(\"button\", name=\"Submit\")" }
{ "locator": "get_by_label(\"Email\")" }
{ "locator": "get_by_text(\"Order confirmed\")" }
{ "locator": "locator(\"#error-banner\")" }
```

For full locator syntax guidance see [Locators](/docs/advanced/locators).
