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.
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.
Related Products
on GumroadDevToolkit Starter Kit
A ready-to-deploy developer tools website with 12 built-in tools. Astro + Preact + Tailwind. Deploy to Cloudflare Pages for free. Built-in SEO, dark mode, and ad-ready layout.
Buy on Gumroad →TypeScript Quick Reference Toolkit
5 practical reference files for TypeScript developers: cheatsheet, TS vs JS comparison, 20 utility types with real examples, tsconfig best practices template, and 15 common mistakes guide. Print it. Keep it on your desk.
Buy on Gumroad →Developer Productivity Bundle
Stop rebuilding the same setup every project. 51 VSCode snippets, 40 Git aliases, 5 Docker Compose stacks, 5 GitHub Actions workflows, 5 README templates, and a dotfiles kit. Set up a professional dev environment in under an hour.
Buy on Gumroad →You Might Also Need
Cypress Frontend Testing Guide
Complete Cypress testing guide for E2E and component testing. Learn cy.visit, cy.get, cy.intercept, custom commands, component testing, and time-travel debugging.
Open free tool →
Jest Testing Framework Guide
Complete guide to Jest JavaScript testing framework. Learn describe/it/expect, mocking, snapshot testing, async tests, coverage, and best practices for unit and integration testing.
Open free tool →
Vitest Guide — Vite-native Testing
Comprehensive Vitest guide for Vite projects. Covers setup, vi.mock, in-source testing, coverage with V8/Istanbul, HMR test running, and migration from Jest.
Open free tool →
More Free Tools
Related Articles
Playwright vs Cypress vs Puppeteer 2026: Which Testing Tool Should You Choose?
Playwright vs Cypress vs Puppeteer 2026 — compare feature sets, performance, developer experience, parallel testing, CI costs, and browser support. Find the right E2E testing tool for your stack.
Playwright vs Cypress vs Selenium: E2E Testing Framework Comparison 2026
Compare Playwright, Cypress, and Selenium for end-to-end testing. Speed, browser support, DX, CI integration, and which framework to choose in 2026.
End-to-End Testing in 2026: Writing Tests That Don't Lie
E2E testing guide 2026: choose Playwright or Cypress, eliminate flakiness, structure test suites for CI/CD, and understand real application quality limits.
Playwright vs Selenium 2026: Which Should You Choose?
Complete comparison of Playwright and Selenium for browser automation and end-to-end testing in 2026. Performance benchmarks, API differences, migration guide, and when to use each.
Playwright vs Cypress vs Puppeteer: E2E Testing in 2026
Comprehensive comparison of Playwright, Cypress, and Puppeteer for end-to-end testing in 2026. Speed, API design, CI/CD integration, cross-browser support, and when to choose each tool.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$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.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →