beer-sakthai/sak-family-agent/saksee-playwright-locator-priority
Claude Code and agent skill by beer-sakthai/sak-family-agent
- community
Checking that the SKILL.md file is still in the repository.
Playwright locator priority: use user-facing locators (role, label, text) instead of CSS/XPath to build resilient tests. Covers the built-in locator hierarchy, filtering, and selector composition.
Install
npx vskill@latest install beer-sakthai/sak-family-agent/saksee-playwright-locator-prioritySKILL.md
Playwright Locator Priority
Concept
Playwright locators are the foundation of auto-waiting and retry-ability. The framework offers a built-in priority of locators; using the right one dramatically reduces flaky tests.
Recommended Locator Priority (highest to lowest)
- `page.getByRole()` — reflects how users and assistive tech perceive the page (button, heading, checkbox, etc.). Pair with
{ name: 'Exact Name' }for precision. - `page.getByLabel()` — for form controls with associated
<label>text. - `page.getByPlaceholder()` — for inputs that have placeholder text but no label.
- `page.getByText()` — for static text content (non-interactive elements).
- `page.getByAltText()` — for images with meaningful alt text.
- `page.getByTitle()` — for elements with a title attribute.
- `page.getByTestId()` — uses
data-testidby default; the most resilient when UI text/roles change. - `page.locator('css=...')` / `page.locator('xpath=...')` — last resort. Tied to DOM structure and breaks easily on refactors.
Code Example
Filtering & Composition
- Filter by text:
page.getByRole('listitem').filter({ hasText: 'Product 2' }) - Filter by descendant:
page.getByRole('listitem').filter({ has: page.getByRole('button', { name: 'Add to cart' }) }) - Negate:
filter({ hasNot: page.getByText('Out of stock') }) - Combine:
page.getByRole('button').and(page.getByTitle('Subscribe')) - Alternatives:
page.getByRole('button', { name: 'New' }).or(dialog).first()
Shadow DOM
All locators pierce open shadow roots automatically. XPath does not. Closed shadow roots are unsupported.
Strictness
Locators are strict: an action like .click() throws if multiple elements match. Explicitly use .first(), .last(), or .nth(i) only when necessary; prefer a tighter locator instead.
When to use
- Authoring new tests from scratch
- Refactoring brittle tests that rely on CSS/XPath
- Deciding which locator strategy to generate in codegen output
- Reviewing PRs that replace role/text locators with CSS selectors
Anti-patterns
- Long CSS chains (
#tsf > div:nth-child(2) > ...) — breaks on markup changes. - XPath expressions tied to layout.
- Using
.click()on a locator that matches multiple elements instead of filtering first.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingpersonas/saksee/skills/SakSee-playwright-locator-priority/SKILL.md
Popularity
- Repository stars
- 1
- Repository forks
- 1
- 7-day trend score
- 8
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/beer-sakthai/sak-family-agent/saksee-playwright-locator-priority)