Playwright Selector Builder
Playwright Selector Builder
Paste HTML, build a locator, and read hit count plus a heuristic stability score before pasting into your spec file.
HTML
Locator
Result
- • Could not parse HTML
TypeScript
await page.getByRole("button", { name: "Sign in" }).click();What This Tool Does
Playwright Selector Builder is built for deterministic developer and agent workflows.
Paste HTML, build getByRole/getByText/getByLabel/CSS/XPath locators, see hit count and a stability score for brittle selectors, copy the ready-to-paste TypeScript snippet.
Use How to Use for execution steps and FAQ for constraints, policies, and edge cases.
Last updated:
This tool is provided as-is for convenience. Output should be verified before use in any production or critical context.
Agent Invocation
Best Path For Builders
Browser workflow
Runs instantly in the browser with private local processing and copy/export-ready output.
Browser Workflow
This tool is optimized for instant in-browser execution with local data handling. Run it here and copy/export the output directly.
/playwright-selector-builder/
For automation planning, fetch the canonical contract at /api/tool/playwright-selector-builder.json.
How to Use Playwright Selector Builder
- 1
Paste your HTML
Drop the HTML snippet you want to test against into the left textarea, or click Load sample to start with a login form. The rendered preview shows what Playwright will see.
- 2
Pick a locator strategy
Choose between getByRole, getByText, getByLabel, getByPlaceholder, CSS, or XPath. The recommended order matches Playwright's official guidance — role-based first, raw selectors last.
- 3
Tune the locator
For role-based locators, pick a role and (optionally) an accessible name. For CSS or XPath, type the selector. Toggle exact match for stricter name matching.
- 4
Read hit count and stability
The Result card shows how many elements match (1 is ideal) and a stability score. Warnings flag nth-child, hashed class names, and other brittle patterns. Copy the TypeScript snippet when you're happy.