Smart Locator Agent
Purpose: Generate stable and maintainable locators for UI automation.
Applicable frameworks:
- Playwright
- Selenium
- Appium
When to Use
Use this skill when:
- Generating locators for new UI elements
- Reviewing existing locators for stability
- Migrating locators between frameworks
Responsibilities
The agent must:
- Inspect the DOM or mobile UI hierarchy (NEVER guess)
- Identify stable attributes
- Generate a reliable locator
- Validate locator uniqueness
- Provide fallback locator if primary is fragile
Locator Priority
Use the following priority order:
- Accessibility attributes (aria-label, role)
data-testid/data-test/data-qaidname- Framework semantic locator
css selectorxpath(last option)
Note: For detailed rules, refer to
.agent/rules/locator_strategy.md.
Playwright Locators
Preferred locator methods:
getByRole()— Best for semantic elementsgetByLabel()— Best for form fields with labelsgetByPlaceholder()— Best for inputs with placeholder textgetByText()— Best for text contentgetByTestId()— Best when data-testid is available
Example:
page.getByRole("button", { name: "Submit" })
page.getByLabel("Email")
page.getByPlaceholder("Enter your password")
Note: For detailed rules, refer to
.agent/rules/playwright_rules.md.
Selenium Locators
Preferred order:
iddata-testidnamecssSelectorxpath
Example:
driver.findElement(By.id("login-button"));
driver.findElement(By.cssSelector("button[data-testid='submit-btn']"));
Note: For detailed rules, refer to
.agent/rules/selenium_rules.md.
Appium Locators
Preferred order:
accessibility idresource-ididiOS predicate stringclass chainxpath
Example:
driver.findElement(AppiumBy.accessibilityId("login_button"));
driver.findElement(AppiumBy.id("com.app:id/login_button"));
driver.findElement(AppiumBy.iOSNsPredicateString("label == 'Login'"));
Note: For detailed rules, refer to
.agent/rules/appium_rules.md.
Validation Rules
Before using a locator, ensure:
- It matches exactly one element
- The element is visible and interactable
- It is stable across page reloads
- It survives cosmetic DOM changes (layout, styling)
- It does NOT use dynamic class names or positional xpath
Output Format
When generating locators, provide:
- Primary locator — The best, most stable option
- Fallback locator — Alternative if primary breaks
- Reasoning — Why this locator was chosen
Rules References
.agent/rules/locator_strategy.md— Master locator priority map.agent/rules/playwright_rules.md— Playwright-specific locator rules.agent/rules/selenium_rules.md— Selenium-specific locator rules.agent/rules/appium_rules.md— Appium-specific locator rules