Selector Types
Priority and Recommendations
1
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.2
Use semantic selectors when the target is obvious
Role selectors are the most reliable for interactive elements. Label selectors are best for form fields.
3
Fall back to text selectors for links and content
bash bap click text:"Learn more" bap click text:"Next page" 4
Use CSS/XPath only when semantic selectors cannot match
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]