Skip to main content

Playwright Selector Tester

Test CSS selectors and generate Playwright locator variants against a pasted HTML snippet. All processing is client-side — no server needed.

✓ CSS selector validation ✓ locator / getByRole / getByText / getByTestId ✓ Match count & element preview

HTML & Selector Input

Results

—
Selector Valid
—
Matching Elements
—
Selector Type

Playwright Locator Variants

Frequently Asked Questions

What is the difference between locator() and getByRole()?▼

locator() accepts CSS selectors, XPath, and Playwright's extended selectors. getByRole() uses ARIA roles to find elements, which is the most robust approach for accessibility testing since it matches how screen readers see the page. Playwright recommends using getByRole() first, then getByText() or getByTestId(), and falling back to CSS selectors only when needed.

What are data-testid attributes and should I use them?▼

data-testid (or data-test-id) are custom HTML attributes added specifically for testing. They don't affect styling or functionality and are stable across refactors. Playwright's getByTestId() defaults to the 'data-testid' attribute but you can configure it. They're ideal for elements that have no unique text or role.

How do I select elements by their text content in Playwright?▼

Use `page.getByText('Submit')` for exact text matching. For partial matches, use `page.getByText('Submit', { exact: false })`. You can also use CSS like `page.locator('button:has-text("Submit")')` or the text= pseudo-selector `page.locator('text=Submit')`.

What makes a good Playwright selector?▼

Good selectors are: (1) user-facing — they target what the user sees, (2) stable — they don't break on minor refactors, (3) unique — they match exactly one element. Avoid selectors based on position (nth-child), auto-generated class names, or implementation details like internal IDs that change between builds.

Can I test selectors without running Playwright?▼

Yes — this tool uses your browser's DOMParser and querySelector to validate selectors against the HTML you paste. For production use, Playwright's codegen tool (`playwright codegen <url>`) records real interactions and generates selectors automatically. The VS Code Playwright extension also has a built-in selector picker.

Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$9/mo after trial · Cancel anytime

Want the full toolkit?

Get DevPlaybook Pro

Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →