Playwright Stable Locators

    1

    Replace brittle CSS and XPath selectors with validated role, label and test-id locators: ranked, checked for exactly one visible match, iframe-aware, never nth(). Zero-dependency toolkit plus the replacement procedure.

    $29

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+22 more

    Playwright Stable Locators

    Example session with this skill installed

    Our checkout e2e tests keep failing on page.locator('div.sc-bdfBwQ > button:nth-child(2)') and xpath=//form/div[3]/input. Replace them with stable Playwright locators and show me the evidence.

    • Read your context and instructions
    • Compiled the playwright stable locators

    Summary

    Two brittle selectors in tests/checkout.spec.ts replaced with validated locators. Each candidate was checked on the live page for exactly one visible match.

    Old selectorReplacementScoreMatchesWhy
    div.sc-bdfBwQ > button:nth-child(2)page.getByRole("button", {"name":"Place order","exact":true})751 visiblerole + accessible name; generated class sc-bdfBwQ rejected
    xpath=//form/div[3]/inputpage.getByLabel("Postal code", {"exact":true})651 visiblelabel association; structural path never emitted

    Rejected candidates: #:r17: (React generated id), text=Place order (2 matches: button and confirmation heading).

    // tests/checkout.spec.ts
    await page.getByLabel("Postal code", { exact: true }).fill("80112");
    await page.getByRole("button", { name: "Place order", exact: true }).click();
    

    Revalidation

    • es-MX locale: getByLabel("Código postal") needed; added a data-testid="postal-code" to the input so one locator works in both locales (test id, score 55).
    • Mobile viewport (390x844): both locators still resolve to one visible element.

    Next steps

    • Run node scripts/selector-toolkit.js --help for the CLI form.
    • Commit evidence/checkout-locators.md (this table) with the PR.
    • Grep the suite for the remaining nth( and xpath= uses: 7 left in tests/account.spec.ts.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Flaky end-to-end suites are mostly selector rot: CSS paths and XPath encode the DOM's shape, which is the thing that changes most. This skill gives your agent a repeatable replacement workflow backed by a zero-dependency toolkit.

    How it works

    From a seed selector on a live page, discoverAndValidate snapshots the element, derives candidates (role + accessible name, label, test id, explicit automation hooks, placeholder, stable id, form name, exact text; never a structural path), rejects generated identifiers (React :r17:, UUIDs, long hex, numeric runs), validates every candidate through Playwright for exactly one visible match, and returns a copyable expression such as page.getByRole("button", {"name":"Save changes","exact":true}) with an evidence table. Nested iframes via options.frame. It never emits nth(), first() or XPath; when nothing validates it tells you which accessibility contract the page is missing.

    What you get

    • scripts/selector-toolkit.js: 402 lines, no dependencies; you supply @playwright/test.
    • A CLI example and 11 unit tests that run without a browser.
    • reference/ranking-policy.md: the candidate scores (role 75, label 65, test id 55 and so on) and the reasoning.
    • reference/safety.md: an authorized-use boundary for running against sites.

    The procedure the agent follows

    1. Find the brittle selectors (nth(, xpath=, :nth-child, generated class names).
    2. Discover and validate a replacement for each on a live page.
    3. Replace with the best validated locator.
    4. Fix the page when nothing validates (add a label, role or test id).
    5. Revalidate across locales and viewports.
    6. Commit the evidence table with the PR.

    Requirements

    Node 20+, Playwright 1.50+.

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Testing & Debugging.

    Requires live page access via Playwright. Static HTML files are not supported. Limited to standard ARIA patterns for accessible name computation. Light DOM focus for snapshots.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed 19 days ago

    Software
    Node.js 20+@playwright/test 1.50+

    @playwright/test must be installed in your project.

    Permissions

    Terminal / Shell
    Browser
    Read Files
    Write Files

    Shell runs node for the toolkit CLI and tests. Read/write files: your test files and an evidence markdown. Browser: Playwright drives a browser against pages you own or are authorized to test (see reference/safety.md). No network calls of its own.

    Listed19 days ago

    What's inside

    Frequently Asked Questions

    This skill automates the migration from brittle CSS/XPath selectors to Playwright’s best-practice locators (like getByRole), which are significantly more resilient to DOM changes and layout refactors.

    Yes, the skill is designed to traverse nested iframe hierarchies and ensure that the generated locators are unique and valid within the specific frame context.

    You will need Node.js 20 or higher and Playwright version 1.50+; the skill integrates directly with your existing Playwright project to validate locators against live browser sessions.

    Unlike general AI models that guess based on static code, this skill performs live validation to ensure every suggested locator matches exactly one visible element, preventing "multiple matches" errors.

    The skill identifies elements that lack proper roles, names, or labels, allowing you to improve your application's accessibility while simultaneously creating more stable tests.

    You receive the complete AI agent skill configuration, including specialized logic for ranking locator candidates and filtering out unstable framework-generated IDs.

    New in Testing & Debugging