Skip to content

Smart Selector Strategy

AutomateX follows Playwright's official recommendations for choosing stable selectors.

The Problem with Selectors

Most test failures aren't bugs — they're broken selectors.

Common issues:

  • CSS classes change with styling updates
  • IDs are auto-generated by frameworks
  • DOM structure changes with refactoring
  • XPath breaks with any hierarchy change

Playwright's Recommendation

From the official Playwright docs:

"We recommend prioritizing user-facing attributes and explicit contracts such as page.getByRole()"

AutomateX Selector Priority

We automatically choose the best selector for each element:

PriorityMethodExampleStability
1getByTestId()data-testid="login-btn"Highest
2getByRole()button with name "Sign In"Highest
3getByLabel()Input with label "Email"High
4getByPlaceholder()Input with placeholderMedium
5getByText()Button containing textMedium
6locator('#id')Stable ID (non-generated)Medium
7locator('.class')CSS class (last resort)Low

Generated ID Detection

AutomateX detects and avoids auto-generated IDs from popular frameworks:

  • React useId() — patterns like :r1:, :r2:
  • Styled Components — patterns like sc-bdnylx
  • CSS-in-JS — patterns like css-1a2b3c
  • Next.js — patterns like __next_123abc
  • Angular — patterns like ng-c-123
  • Ember — patterns like ember123

These are automatically skipped in favor of more stable alternatives.

Duplicate Selector Handling

When multiple elements share the same label or text, AutomateX:

  1. Tries alternative selector strategies (placeholder, name, ID)
  2. Falls back to .nth() disambiguation if all strategies collide
  3. Lowers confidence scores to flag these for manual review

Warnings for Fragile Selectors

When stable selectors aren't available, AutomateX warns you:

Warning: 3 elements missing data-testid.
Consider adding for stable selectors.

This helps you improve testability over time.


Focus Selector

For pages with complex navigation, limit detection to the main content area:

--focus-selector="main"
--focus-selector=".content"
--focus-selector="#app"

This automatically excludes headers, footers, and navigation — generating page objects only for the content you care about.


Stop Fighting Selectors

Let AutomateX pick the right selector every time.

Request Early Access

Built for QA Engineers