Skip to main content

Cypress Selector Helper

Build resilient Cypress selectors and data-cy attributes. Paste HTML or describe your element to get ready-to-use cy.get() commands.

✓ data-cy strategy ✓ CSS selector builder ✓ Selector strength rating ✓ Copy-ready code

Paste HTML Element

Manual Builder

Selector Options (Best → Worst)

Generated Cypress Code

 

Updated HTML

 

Frequently Asked Questions

What is the recommended selector strategy for Cypress tests?▼

Cypress recommends data-cy attributes (e.g., data-cy='submit-button') as the most resilient selector strategy. CSS classes and IDs change during refactoring, breaking tests. data-cy attributes are test-specific and communicate intent clearly. They decouple test selectors from presentation concerns. If you can't add data-cy attributes, prefer role-based selectors (cy.findByRole) or accessible text selectors over CSS classes.

What is the difference between cy.get() and cy.find()?▼

cy.get() queries the entire DOM from the root. cy.find() queries within a previously selected element. Use cy.find() to scope searches: cy.get('[data-cy=form]').find('input') finds all inputs inside the form element. This makes tests more precise and less likely to accidentally target the wrong element when similar elements exist elsewhere on the page.

How do I select elements that don't have text content?▼

For elements without visible text (icons, buttons with only SVGs, inputs), use: data-cy attributes (recommended), aria-label for accessibility-compliant elements ('cy.get([aria-label=Close])'), type attribute for inputs ('cy.get(input[type=email])'), or placeholder text ('cy.get(input[placeholder=Email address])'). Avoid selecting by CSS class alone as it's brittle.

How do I handle dynamic content and async loading in Cypress?▼

Cypress automatically retries commands for up to 4 seconds (configurable via defaultCommandTimeout). For content that loads via API calls, use cy.intercept() to wait for network requests: cy.intercept('GET', '/api/users').as('getUsers'); cy.wait('@getUsers'). This is more reliable than cy.wait(3000) hardcoded delays. For animations, use cy.contains(':visible') to wait for element visibility.

What is Testing Library's cy.findBy* and should I use it?▼

cy.findByRole, cy.findByText, cy.findByLabelText etc. come from the @testing-library/cypress plugin. They encourage accessibility-first selectors — selecting elements the way real users interact with them. cy.findByRole('button', { name: 'Submit' }) is more resilient than cy.get('[data-cy=submit]') and doubles as an accessibility check. Install @testing-library/cypress and add to support/commands.ts for best results.

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 →