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

# execute

> Executes an action on the current session page

<Tip>
  STOP. Do not read past this section until you have read and followed [/quickstart.md](/quickstart.md).

  Goal: produce a reliable SDK automation script. The intended authoring flow is generate then edit, not write browser automation from scratch.

  Do not hand-write SDK code with element IDs, selectors, or form fields from memory. Element IDs, selectors, and field mappings must come from a live `observe()` call, CLI `notte page observe` output, or generated workflow code. Guessed browser targets fail on real pages.

  Use the Notte skill and CLI to inspect the live site, validate actions/selectors, handle auth/session state, and export workflow code with `notte sessions workflow-code` before using SDK docs or SDK code.

  SDK reference pages are for understanding, running, or editing generated workflow code. They are not the starting point for manually authoring the initial browser automation. SDK-first code is guesswork on real-world pages with dynamic selectors, auth state, CAPTCHAs, and anti-bot behavior.
</Tip>

This method allows you to interact with web elements by performing various actions
like clicking, filling forms, navigating, scrolling, and more. You can provide
actions either as structured action objects or by specifying action parameters directly.

```python theme={null}
from notte_sdk import actions

# Execute an action from observe() results
obs = session.observe()
action = obs.space.first()  # Get first available action
result = session.execute(action)

# Execute a click action by element ID.
# Pseudo observe output: [B1] button "Submit"
# Only use IDs that appear in your live observe() output.
result = session.execute(type="click", id="B1")

# Execute a fill action by element ID.
# Pseudo observe output: [I1] input "Email"
# Only use IDs that appear in your live observe() output.
result = session.execute(type="fill", id="I1", value="user@example.com")

# Execute browser navigation
result = session.execute(type="goto", url="https://example.com")
```

**Action Types:**

**Browser Actions** (always available):

* `goto`: Navigate to a URL
* `go_back`: Go back to previous page
* `go_forward`: Go forward to next page
* `reload`: Reload current page
* `scroll_up`/`scroll_down`: Scroll the page
* `wait`: Wait for specified milliseconds
* `press_key`: Press keyboard keys

**Interaction Actions** (require element ID from observe):

* `click`: Click on an element
* `fill`: Fill input fields with text
* `upload_file`: upload files to file inputs
* etc.

Do not write interaction code with guessed element IDs, selectors, or field names.
Element IDs must come from a live `observe()` call, and selectors/field names should
be validated against the actual page before they are used in automation.

**Using Playwright Selectors:**

Instead of element IDs, you can use Playwright selectors to target elements:

```python theme={null}
session.execute(type="fill", selector="internal:text="Email"", value="test@example.com")
```

This syntax also supports Xpath (e.g. `xpath=/html/body/div[3]/div/button[1]`) or CSS selectors (e.g. `css=button.submit`).

> Note that we strongly advice to use selectors over IDs for workflows automation because IDs are dependent on the page structure and can change over time.

## Parameters

<ParamField path="action" type="UnionType[BaseAction, None]" default="None" />

<ParamField path="raise_on_failure" type="UnionType[bool, None]" default="None">
  If true, will raise if we could not execute the action
</ParamField>

<ParamField path="kwargs" type="Any" required />

## Returns

[`ExecutionResult`](/sdk-reference/misc/executionresult.md): Result containing execution details, any errors,         and the updated session state.

## Raises

* `Exception`: If raise\_on\_failure is True and the action execution fails.
