type field and type-specific properties. Selectors are used throughout the protocol in action methods, observations, and extraction.
Selector Types
| Type | Stability | Best For |
|---|---|---|
testId | Highest | Elements with data-testid attributes |
role | High | Buttons, textboxes, links by ARIA role + name |
ref | High | Stable references from agent/observe output |
label | High | Form inputs with associated labels |
text | Medium | Elements with visible text content |
placeholder | Medium | Inputs with placeholder text |
css | Low | Direct CSS selectors |
xpath | Low | XPath expressions |
semantic | Variable | AI-resolved natural language descriptions |
coordinates | Lowest | Pixel coordinates (last resort) |
JSON Format
testId
Target elements by theirdata-testid attribute. Most resilient to redesigns.
role
Target elements by ARIA role and optional accessible name. The recommended default for interactive elements.button, textbox, link, checkbox, combobox, heading, tab, menuitem.
ref
Use stable references returned byagent/observe. Refs persist across observations for the same element.
text
Match elements by their visible text content (case-sensitive).label
Target form inputs by their associated<label> text.
placeholder
Target inputs by their placeholder text.testId
Target elements bydata-testid attribute.
css
Direct CSS selector. Use when semantic selectors are insufficient.CSS selectors are brittle — they break when the DOM structure changes. Prefer semantic selectors
when possible.
xpath
XPath expression for complex DOM traversals.semantic
Natural language description of the target element. The server resolves this to a concrete selector using accessibility tree analysis.coordinates
Pixel coordinates on the page. Use as a last resort when no other selector type works.Alternative Selectors
EachInteractiveElement returned by agent/observe includes an optional alternativeSelectors array — multiple selector options ordered by reliability (most reliable first):
- testId —
data-testidattribute (most stable, survives redesigns) - role + name — ARIA role with accessible name
- css #id — Element ID (escaped for CSS special chars)
- text — Visible text content (if under 50 characters)
- css path — Full CSS path (least stable, but always unique)
selector field contains the best available option.
Selector Resolution Priority
When the server receives a selector, it resolves it in this order:- Cached CSS selector — If the element was previously observed, the cached CSS path is used first (fastest)
- Direct resolution — The selector is resolved against the current DOM
- Self-healing fallback — If the primary selector fails, the server tries fallback identity signals:
testIdthenariaLabel+rolethenidthenname
SDK Helpers
Both the TypeScript and Python SDKs provide factory functions for building selectors:- TypeScript
- Python