Selector Types
| Type | Syntax | Example | When to use |
|---|---|---|---|
| Stable ref | @<ref> | @submitBtn | Refs returned by bap observe — most precise |
| Positional ref | e<N> | e15 | From snapshot refs (playwright-cli compatible) |
| Role | role:<role>:"<name>" | role:button:"Submit" | Interactive elements by ARIA role — most reliable |
| Text | text:"<content>" | text:"Sign in" | By visible text content |
| Label | label:"<text>" | label:"Email" | Form inputs by associated label |
| Placeholder | placeholder:"<text>" | placeholder:"Search..." | Inputs by placeholder attribute |
| Test ID | testid:"<id>" | testid:"submit-btn" | By data-testid — most stable for apps that use them |
| CSS | css:<selector> | css:.btn-primary | CSS selector (fallback) |
| XPath | xpath:<path> | xpath://button[@type] | XPath selector (fallback) |
| Coordinates | coords:<x>,<y> | coords:100,200 | Click by pixel coordinates (last resort) |
Priority and Recommendations
Start with stable refs from observe
Run
bap observe and use the exact @ref values it returns. These are the most precise selectors because they map to a specific element in the registry.Use semantic selectors when the target is obvious
Role selectors are the most reliable for interactive elements. Label selectors are best for form fields.
Fall back to text selectors for links and content
bash bap click text:"Learn more" bap click text:"Next page" Using Selectors in Commands
Single commands
In composite actions (bap act)
The step syntax is action:selector=value for fill/type and action:selector for click/check/hover:
In the TypeScript SDK
In the Python SDK
In MCP tools
Role Selector Examples
The role selector uses ARIA roles, which cover most interactive elements:Disambiguation
When multiple elements match a selector, BAP returns the first visible, interactive match. To disambiguate:- Use a more specific role (e.g.,
role:button:"Submit"instead oftext:"Submit") - Run
bap observe --max=100to see all candidates and use the exact@ref - Combine with CSS if needed:
css:#login-form button[type=submit]