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.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>
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
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
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
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.

