Skip to main content
Create a Locator from a page selector, then reuse it for element interactions and state queries. first() and nth() refine the local locator descriptor; the resulting descriptor is sent with later operations. Selectors pierce shadow DOM, including closed roots. Selectors also cross iframe boundaries. Separate a frame from a target inside it with >>, and Stagehand resolves each hop in turn, so page.locator("iframe#checkout >> button.submit") reaches the button inside that iframe. Chain as many hops as the page nests. A deep XPath that steps through an iframe resolves the same way, as in /html/body/iframe[2]//div.
Closed roots require a navigated page. Stagehand resolves elements inside iframes and shadow DOMs for you, so you rarely need to target nested documents manually. This relies on privileged browser APIs that aren’t available on about:blank or data: URLs, so navigate to a http: or https: URL first when a target sits inside an iframe or a closed shadow root (see locator limitations).

Quick start

Each locator call has a 20-second timeout covering frame readiness, element lookup, & the action itself. Typing delays & highlight duration count toward the same budget. File reading in the SDK & request delivery happen before that budget starts. A timeout stops further steps; it cannot undo browser commands already sent.

click()

Click the element matched by this locator.
LocatorClickOptions
Options that configure this operation.
number
The timeout for the whole call in milliseconds. Defaults to 20,000. Set to 0 to disable it.
MouseButton
The mouse button to use: "left", "middle", or "right".
number
The number of clicks to dispatch.
Promise<void>
Resolves after the operation completes.

hover()

Move the pointer over the matched element.
LocatorOptions
Options that configure this operation.
number
The timeout for the whole call in milliseconds. Defaults to 20,000. Set to 0 to disable it.
Promise<void>
Resolves after the operation completes.

fill()

Replace the matched input’s value.
string
The value to set.
LocatorOptions
Options that configure this operation.
number
The timeout for the whole call in milliseconds. Defaults to 20,000. Set to 0 to disable it.
Promise<void>
Resolves after the operation completes.

count()

Count the elements matched by this locator.
LocatorOptions
Options that configure this operation.
number
The timeout for the whole call in milliseconds. Defaults to 20,000. Set to 0 to disable it.
Promise<number>
The operation result.

isChecked()

Check whether the matched control is checked.
LocatorOptions
Options that configure this operation.
number
The timeout for the whole call in milliseconds. Defaults to 20,000. Set to 0 to disable it.
Promise<boolean>
The operation result.

inputValue()

Return the current value of the matched input.
LocatorOptions
Options that configure this operation.
number
The timeout for the whole call in milliseconds. Defaults to 20,000. Set to 0 to disable it.
Promise<string>
The operation result.

isVisible()

Check whether the matched element is visible.
LocatorOptions
Options that configure this operation.
number
The timeout for the whole call in milliseconds. Defaults to 20,000. Set to 0 to disable it.
Promise<boolean>
The operation result.

innerText()

Return the rendered text inside the matched element.
LocatorOptions
Options that configure this operation.
number
The timeout for the whole call in milliseconds. Defaults to 20,000. Set to 0 to disable it.
Promise<string>
The operation result.

innerHtml()

Return the HTML inside the matched element.
LocatorOptions
Options that configure this operation.
number
The timeout for the whole call in milliseconds. Defaults to 20,000. Set to 0 to disable it.
Promise<string>
The operation result.

textContent()

Return the text content of the matched element.
LocatorOptions
Options that configure this operation.
number
The timeout for the whole call in milliseconds. Defaults to 20,000. Set to 0 to disable it.
Promise<string>
The operation result.

scrollTo()

Scroll the matched element to a percentage of its range.
number | string
A percentage from 0 to 100, optionally expressed as a percentage string.
LocatorOptions
Options that configure this operation.
number
The timeout for the whole call in milliseconds. Defaults to 20,000. Set to 0 to disable it.
Promise<void>
Resolves after the operation completes.

centroid()

Return the center point of the matched element.
LocatorOptions
Options that configure this operation.
number
The timeout for the whole call in milliseconds. Defaults to 20,000. Set to 0 to disable it.
Promise<LocatorCentroidResult>
The operation result.
number
The horizontal center coordinate.
number
The vertical center coordinate.

highlight()

Temporarily highlight the matched element.
LocatorHighlightOptions
Options that configure this operation.
number
The timeout for the whole call in milliseconds. Defaults to 20,000. Set to 0 to disable it.
RgbaColor
The highlight border color.
number
The alpha channel.
number
The blue channel.
number
The green channel.
number
The red channel.
RgbaColor
The highlight fill color.
number
The alpha channel.
number
The blue channel.
number
The green channel.
number
The red channel.
number
How long to display the highlight.
Promise<void>
Resolves after the operation completes.

sendClickEvent()

Dispatch a DOM click event on the matched element.
LocatorSendClickEventOptions
Options that configure this operation.
number
The timeout for the whole call in milliseconds. Defaults to 20,000. Set to 0 to disable it.
boolean
Whether the event bubbles.
boolean
Whether the event can be canceled.
boolean
Whether the event crosses shadow DOM boundaries.
number
The event-specific click detail.
Promise<void>
Resolves after the operation completes.

type()

Type text into the matched element.
string
The text to type.
LocatorTypeOptions
Options that configure this operation.
number
The timeout for the whole call in milliseconds. Defaults to 20,000. Set to 0 to disable it.
number
The input delay in milliseconds.
Promise<void>
Resolves after the operation completes.

selectOption()

Select one or more values in the matched select element.
string | string[]
The value or values to select.
LocatorOptions
Options that configure this operation.
number
The timeout for the whole call in milliseconds. Defaults to 20,000. Set to 0 to disable it.
Promise<string[]>
The operation result.

setInputFiles()

Set one or more local files or in-memory payloads on the matched <input type="file">. The SDK resolves relative paths on the caller’s machine. Pass an empty array to clear the selection.
FileInput
Local file path(s) or in-memory payload(s) to upload. The SDK serializes each file in memory and limits it to 50 MiB.
string
The filename exposed to the page.
string
The file’s MIME type.
ArrayBuffer | Uint8Array | string
The in-memory file content to upload. The SDK base64-encodes it for transport.
number
The file’s last-modified time in Unix milliseconds.
LocatorOptions
Options that configure this operation.
number
The timeout for the whole call in milliseconds. Defaults to 20,000. Set to 0 to disable it.
Promise<void>
Resolves after the files are attached.

first()

Create a locator for the first matching element.
Locator
The operation result.

nth()

Create a locator for a matching element at a zero-based index.
number
The zero-based match index.
Locator
The operation result.