Playwright Selector Builder
Test getByRole, getByText, getByLabel, getByPlaceholder, CSS or XPath Playwright locators on pasted HTML, with match count and a stability score.
Playwright Selector Builder
HTML
Locator
Result
TypeScript
await page.getByRole("button", { name: "Sign in" }).click();Updated . Provided as is. Check the output before you rely on it in production.
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.
Questions and answers
What is Playwright Selector Builder?
How is the stability score calculated?
Does it actually run Playwright?
Does it send my HTML to a server?
Which roles does getByRole support?
For AI agents: how to call this tool
Machine-readable contract, endpoints and examples. Humans can ignore this section.
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.