| name | Smart Locator Agent |
| description | Skill sinh locator ổn định và dễ bảo trì cho UI automation, hỗ trợ Playwright, Selenium và Appium. |
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-qa
id
name
- Framework semantic locator
css selector
xpath (last option)
Note: For detailed rules, refer to .claude/rules/locator_strategy.md.
Playwright Locators
Preferred locator methods:
getByRole() — Best for semantic elements
getByLabel() — Best for form fields with labels
getByPlaceholder() — Best for inputs with placeholder text
getByText() — Best for text content
getByTestId() — 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 .claude/rules/playwright_rules.md.
Selenium Locators
Preferred order:
id
data-testid
name
cssSelector
xpath
Example:
driver.findElement(By.id("login-button"));
driver.findElement(By.cssSelector("button[data-testid='submit-btn']"));
Note: For detailed rules, refer to .claude/rules/selenium_rules.md.
Appium Locators
Preferred order:
accessibility id
resource-id
id
iOS predicate string
class chain
xpath
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 .claude/rules/appium_rules.md.
Validation Rules
Before using a locator, ensure:
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
.claude/rules/locator_strategy.md — Master locator priority map
.claude/rules/playwright_rules.md — Playwright-specific locator rules
.claude/rules/selenium_rules.md — Selenium-specific locator rules
.claude/rules/appium_rules.md — Appium-specific locator rules