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.
- TypeScript
- Python
- Go
Quick start
click()
Click the element matched by this locator.LocatorClickOptions
Promise<void>
Resolves after the operation completes.
hover()
Move the pointer over the matched element.Promise<void>
Resolves after the operation completes.
fill()
Replace the matched input’s value.string
The value to set.
Promise<void>
Resolves after the operation completes.
count()
Count the elements matched by this locator.Promise<number>
The operation result.
isChecked()
Check whether the matched control is checked.Promise<boolean>
The operation result.
inputValue()
Return the current value of the matched input.Promise<string>
The operation result.
isVisible()
Check whether the matched element is visible.Promise<boolean>
The operation result.
innerText()
Return the rendered text inside the matched element.Promise<string>
The operation result.
innerHtml()
Return the HTML inside the matched element.Promise<string>
The operation result.
textContent()
Return the text content of the matched element.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.
Promise<void>
Resolves after the operation completes.
centroid()
Return the center point of the matched element.Promise<LocatorCentroidResult>
highlight()
Temporarily highlight the matched element.LocatorHighlightOptions
Options that configure this operation.
RgbaColor
RgbaColor
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
Promise<void>
Resolves after the operation completes.
type()
Type text into the matched element.string
The text to type.
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.
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.
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.

