Playwright & Puppeteer Selector Builder
Paste HTML and copy uniqueness-verified locators.
Input
1 line · 23 charsResult
Selector Builder sanitizes pasted HTML, renders it in an isolated preview, and generates candidate locators for whichever element you click. Every candidate is verified against the live preview document, so the badge tells you whether it matches exactly one element, several, or none. Strategies are ranked by resilience: role and accessible name first, then test id, label, text, id/CSS, and finally a minimized structural path with XPath as a fallback. Switch between Playwright and Puppeteer output and copy a single locator or the whole annotated snippet. Nothing is uploaded; scripts in pasted markup are stripped before rendering.
Examples
<button data-testid="save">Save</button>page.getByRole("button", { name: "Save" })Role and name is preferred because it mirrors how users find the control.
<label for="e">Email</label><input id="e">page.getByLabel("Email")Label association is resolved from for/id and from wrapping labels.
<div><span>Plain</span></div>body > div > spanWith no accessible name or test id, a minimized unique CSS path is the honest fallback.
About this tool
The Playwright & Puppeteer Selector Builder turns a pasted HTML fragment into a shortlist of locators for one clicked element. Rather than guessing from the markup text, it runs each candidate against the rendered preview and reports how many elements actually match, so a "unique" claim is always backed by a live query.
Candidates follow the resilience order used in maintainable test suites: role with accessible name, test id, associated label, visible text, a stable id or attribute selector, and only then a minimized structural CSS path or XPath. Each card explains why it is stable or brittle, so you can make an informed choice instead of copying the first result.
The preview is built from sanitized markup with scripts and navigation vectors removed. Generation, verification, and snippet emission all happen in your browser; the HTML never leaves the tab.
What this tool does not do
- Accessible name computation is a documented subset of the ARIA algorithm, not a full conformance implementation.
- XPath verification depends on document.evaluate; where unavailable, XPath cards are marked unverified rather than claiming a match count.
- Only pasted markup is inspected — live applications, shadow roots closed to the preview, and framework-authored DOM are out of scope.
How to use this tool
Paste HTML
Paste a fragment or full document into the HTML panel, or load an example chip. Inline scripts and meta refresh tags are stripped before the preview is built.
Select an element
Click an element in the preview, or choose one from the keyboard-accessible element list. The selected element is outlined and its tag summary is shown as text.
Review ranked strategies
Each card shows a code snippet, a framework chip, a uniqueness badge (exact-1, matches-N or 0) and a rationale explaining how likely it is to survive DOM changes.
Copy a snippet
Copy one strategy or the whole annotated snippet. Switch between Playwright and Puppeteer output and configure the test id attribute before copying.
Use cases
Harden recorded tests
Replace nth-child paths recorded by browser extensions with role, label, or test id locators that are verified unique in the same preview.
Design a test-id strategy
See which elements lack a stable hook, then add data-testid attributes where generated CSS paths are the only option.
Puppeteer fallbacks
Get CSS and XPath strategies with idiomatic Puppeteer query syntax when Playwright locators are not available.
Strategy families
| Family | Example output |
|---|---|
| Role + name | page.getByRole("button", { name: "Submit order" }) |
| Test id | page.getByTestId("checkout-cta") |
| Label | page.getByLabel("Email address") |
| Text | page.getByText("Submit order", { exact: true }) |
| CSS path | main > form > button[type="submit"] |
| XPath | //button[@type="submit"] |
A badge of "exact-1" means one live match in the preview; a duplicate name is reported as matches-N with disambiguation guidance.
Common mistakes
Mistake:Copying a brittle nth-child path when a role strategy is available.
Fix:Prefer the top-ranked card: role and accessible name track what the user sees, while structural paths break when a wrapper is added.
Mistake:Ignoring a matches-N badge.
Fix:A locator matching several elements will fail strict mode at runtime. Use the disambiguation hint, add a test id, or scope the locator to a parent.
Mistake:Changing the test id attribute but copying getByTestId anyway.
Fix:Playwright reads data-testid by default. When you configure another attribute, copy the emitted CSS fallback or set testIdAttribute in your Playwright config.
Frequently asked questions
Which selector should I prefer?
Take the top-ranked strategy that is verified as exact-1. Role with an accessible name is usually best because it reflects what a user sees and survives class or wrapper changes. Test ids and labels are also strong; text is reasonable when copy is stable; structural CSS paths and XPath are last-resort fallbacks.
How is the accessible name computed?
The tool follows the common precedence: aria-labelledby is resolved first, then aria-label, then native semantics such as a label associated with an input, button or link text, and image alt text. Placeholder text is never used as an accessible name; it is offered as a separate placeholder strategy where appropriate.
Are selectors really verified as unique?
Yes. CSS candidates are checked with querySelectorAll against the preview document, and role or text candidates are checked with an equivalent filtered walk. The badge reports the live count: exact-1, matches-N, or 0. Candidates that cannot be verified, such as XPath where document.evaluate is unavailable, are labelled accordingly instead of being given a false badge.
Does it work for Puppeteer?
Yes. Puppeteer mode emits idiomatic single-element queries (page.$ / page.waitForSelector) for CSS and text pseudo-selectors, with a note when a Playwright-only locator family has no direct Puppeteer equivalent.
Can I customize the test id attribute?
Yes. Set the test id attribute field before copying. For Playwright, the emitted snippet includes a note that your config needs testIdAttribute set to the same value; otherwise a CSS attribute selector is provided as a drop-in fallback.
References & standards
Related tools
.env Secret Safety Linter
Validate .env syntax and spot likely leaked credentials or placeholder secrets.
.gitattributes Generator
Build .gitattributes rules for line endings, Git LFS, GitHub linguist marks and merge drivers — with a one-line explanation for every rule.
.htaccess Generator
Build an Apache .htaccess — HTTPS redirects, rewrites, error pages, security headers, and basic auth
2D Fluid Dynamics & Particle Physics Sandbox
A physics playground with two engines sharing one canvas. The fluid mode runs a real Eulerian Navier-Stokes solver — semi-Lagrangian advection, explicit diffusion, Jacobi pressure projection and vorticity confinement — that you paint with dye and velocity using mouse or touch. The particle mode is a damped Verlet N-body engine with gravity wells, Coulomb attractors and repulsors, spring links, wall restitution and elastic circle collisions. Particle counts adapt to the device (100k target on WebGL2 desktop, 2k-5k on CPU fallback), and every configuration exports as runnable code: a Matter.js world, a PixiJS ticker setup, or a standalone vanilla Canvas engine.
A/B Test Sample Size Calculator
Compute required sample size per variant and test duration from baseline conversion rate, minimum detectable effect, alpha and power.
ABA Routing Number Validator
Validate 9-digit US ABA routing numbers with 3-7-1 Mod-10 breakdown.