*** title: Stagehand Locator description: Complete Locator method reference for the Stagehand driver. ------------------------------------------------------------------------ All `Locator` methods available when using the **Stagehand** driver. Access via `runtime.page.locator(...)` after launching a Stagehand runtime. Every method below is a remote call. The SDK translates it into a structured step sent to a single endpoint: ``` POST /v1/workspaces/{workspaceId}/execute ``` ```json { "runtime": "my-browser", "steps": [ { "call": "locator.goto", "args": ["https://example.com"] } ] } ``` The `call` field maps directly to the method name. `args` is a JSON array of the method's arguments. You can batch multiple steps in one request. ## Actions ### click(options?) Click the element at its visual center. The method: 1. Scrolls element into view 2. Gets element geometry 3. Moves mouse to center 4. Dispatches mousePressed and mouseReleased events Options include: * button: 'left' | 'right' | 'middle' (default: 'left') * clickCount: Number of clicks (default: 1) ```ts await locator.click(); ``` | Parameter | Type | Required | Description | | --------- | ------------------------------ | -------- | ----------- | | `options` | `StagehandLocatorClickOptions` | No | — | [Upstream docs](https://docs.stagehand.dev/references/locator#click) *** ### fill(value) Fill an input, textarea, or contenteditable element. The method intelligently handles different input types: * Uses native value setter for special inputs (date, number, etc.) * Types text character-by-character for regular inputs * Clears existing content before filling ```ts await locator.fill("user@example.com"); ``` | Parameter | Type | Required | Description | | --------- | -------- | -------- | ---------------------------------------- | | `value` | `string` | Yes | The text value to fill into the element. | [Upstream docs](https://docs.stagehand.dev/references/locator#fill) *** ### type(text, options?) Type text into the element with optional delay between keystrokes. If delay is not specified, uses Input.insertText for efficiency. ```ts await locator.type("Hello"); ``` | Parameter | Type | Required | Description | | --------- | ----------------------------- | -------- | ----------------- | | `text` | `string` | Yes | The text to type. | | `options` | `StagehandLocatorTypeOptions` | No | — | [Upstream docs](https://docs.stagehand.dev/references/locator#type) *** ### hover() Move the mouse cursor to the element's center without clicking. Scrolls the element into view and dispatches a mouse move event. ```ts await locator.hover(); ``` [Upstream docs](https://docs.stagehand.dev/references/locator#hover) *** ### selectOption(values) Select one or more options in a \ element. Accepts: * File path (string) * Array of file paths * File payload object \{ name, mimeType, buffer } * Array of file payloads Pass an empty array to clear the file selection. ```ts await locator.setInputFiles("./file.pdf"); ``` | Parameter | Type | Required | Description | | --------- | -------------------- | -------- | -------------------------------------- | | `files` | `StagehandFileInput` | Yes | File paths or file payloads to upload. | [Upstream docs](https://docs.stagehand.dev/references/locator#setinputfiles) *** ### highlight(options?) Visually highlight the element with an overlay. Useful for debugging and visual verification. Options include: * durationMs: How long to display the highlight (default: 800) * borderColor: Border color RGBA values * contentColor: Content fill color RGBA values ```ts await locator.highlight(); ``` | Parameter | Type | Required | Description | | --------- | --------------------------- | -------- | ----------- | | `options` | `StagehandHighlightOptions` | No | — | [Upstream docs](https://docs.stagehand.dev/references/locator#highlight) *** ### scrollTo(percent) Scroll the element to a specific position. For \ or \ elements, scrolls the window. Otherwise, scrolls the element itself. ```ts await locator.scrollTo(50); // Scroll to 50% ``` | Parameter | Type | Required | Description | | --------- | ------------------ | -------- | -------------------------------------- | | `percent` | `number \| string` | Yes | Scroll position as percentage (0-100). | [Upstream docs](https://docs.stagehand.dev/references/locator#scrollto) *** ### centroid() Get the center coordinates of the element. ```ts const { x, y } = await locator.centroid(); ``` **Returns** `{ x: number; y: number }` — Center point in CSS pixels \{ x, y }. [Upstream docs](https://docs.stagehand.dev/references/locator#centroid) *** ### sendClickEvent(options?) Dispatch a DOM click event directly on the element. This dispatches an event directly without synthesizing real pointer input. Useful for elements that rely on click handlers without needing hit-testing. Options include: * bubbles: Whether the event bubbles (default: true) * cancelable: Whether the event is cancelable (default: true) * composed: Whether the event crosses shadow DOM boundaries (default: true) * detail: Click count detail (default: 1) ```ts await locator.sendClickEvent(); ``` | Parameter | Type | Required | Description | | --------- | -------------------------------- | -------- | ----------- | | `options` | `StagehandSendClickEventOptions` | No | — | [Upstream docs](https://docs.stagehand.dev/references/locator#sendclickevent) *** ## Queries ### count() Return the number of elements matching this locator. ```ts const count = await locator.count(); ``` **Returns** `number` [Upstream docs](https://docs.stagehand.dev/references/locator#count) *** ### nth(index) Return a locator for the nth matching element. Index is zero-based. ```ts const secondItem = locator.nth(1); ``` | Parameter | Type | Required | Description | | --------- | -------- | -------- | -------------------------------- | | `index` | `number` | Yes | Zero-based index of the element. | **Returns** `RemoteStagehandLocator` [Upstream docs](https://docs.stagehand.dev/references/locator#nth) *** ### first() Return a locator for the first matching element. ```ts const firstItem = locator.first(); ``` **Returns** `RemoteStagehandLocator` [Upstream docs](https://docs.stagehand.dev/references/locator#first) *** ## Content ### inputValue() Get the current value of an input element. Works with: \, \