- Home
- Skills
- Testing & Debugging
- Playwright Stable Locators
Playwright Stable Locators
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
Works with the AI Agents you already use
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 selector | Replacement | Score | Matches | Why |
|---|---|---|---|---|
div.sc-bdfBwQ > button:nth-child(2) | page.getByRole("button", {"name":"Place order","exact":true}) | 75 | 1 visible | role + accessible name; generated class sc-bdfBwQ rejected |
xpath=//form/div[3]/input | page.getByLabel("Postal code", {"exact":true}) | 65 | 1 visible | label 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 adata-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 --helpfor the CLI form. - Commit
evidence/checkout-locators.md(this table) with the PR. - Grep the suite for the remaining
nth(andxpath=uses: 7 left intests/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
- Find the brittle selectors (
nth(,xpath=,:nth-child, generated class names). - Discover and validate a replacement for each on a live page.
- Replace with the best validated locator.
- Fix the page when nothing validates (add a label, role or test id).
- Revalidate across locales and viewports.
- 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
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
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 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
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.