Skip to main content
BAP uses semantic selectors that describe elements by their purpose instead of their DOM position. They survive layout changes, dynamic content updates, and A/B tests.

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:
  1. Use a more specific role (e.g., role:button:"Submit" instead of text:"Submit")
  2. Run bap observe --max=100 to see all candidates and use the exact @ref
  3. Combine with CSS if needed: css:#login-form button[type=submit]
Identical elements (e.g., six “Add to cart” buttons) produce ambiguous text:Add to cart selectors. Use the specific @ref from bap observe or a CSS selector with an ID to target the right one.

Fallback Behavior

If a semantic selector does not match, BAP returns a clear error message with the closest matches found on the page, helping the agent self-correct.