beer-sakthai/sak-family-agent/saksee-playwright-locator-priority

Claude Code and agent skill by beer-sakthai/sak-family-agent

Trust tier 3
  • community
Source check pending

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-priority

SKILL.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)

  1. `page.getByRole()` — reflects how users and assistive tech perceive the page (button, heading, checkbox, etc.). Pair with { name: 'Exact Name' } for precision.
  2. `page.getByLabel()` — for form controls with associated <label> text.
  3. `page.getByPlaceholder()` — for inputs that have placeholder text but no label.
  4. `page.getByText()` — for static text content (non-interactive elements).
  5. `page.getByAltText()` — for images with meaningful alt text.
  6. `page.getByTitle()` — for elements with a title attribute.
  7. `page.getByTestId()` — uses data-testid by default; the most resilient when UI text/roles change.
  8. `page.locator('css=...')` / `page.locator('xpath=...')` — last resort. Tied to DOM structure and breaks easily on refactors.

Code Example

ts
import { test, expect } from '@playwright/test';
test('login flow with prioritized locators', async ({ page }) => {
await page.goto('https://example.com/login');
await page.getByLabel('User Name').fill('john');
await page.getByLabel('Password').fill('secret');
await page.getByRole('button', { name: 'Sign in' }).click();
await expect(page.getByText('Welcome, John')).toBeVisible();
});

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

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
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/beer-sakthai/sak-family-agent/saksee-playwright-locator-priority/badge)](https://verified-skill.com/skills/beer-sakthai/sak-family-agent/saksee-playwright-locator-priority)

Something wrong with this skill or its page? Tell us.