DEV Community

Cover image for Selecting elements in Cypress tests: basic + advanced patterns (2 useful Cheatsheets)
Alex Sanzhanov
Alex Sanzhanov

Posted on • Edited on

6 2 1 1

Selecting elements in Cypress tests: basic + advanced patterns (2 useful Cheatsheets)

Greetings to all Cypress enthusiasts!

In this very short note, I would like to share with you one very useful thing for selecting elements in Cypress tests. To be honest, I had plans for a long time to summarize the most common CSS and jQuery selector patterns, which in fact was the reason for creating this extensive table. You can of course use the great Cypress built-in commands like contains(), find(), eq(), etc. to select test elements. However, skillfully combining element attributes, binding to pseudo-classes and the current state of elements, using a hierarchy and combinators, and so on can give you additional advantages and ensure reliability in choosing DOM elements.

Well, I present to you my cheatsheets with basic and advanced selector patterns and examples of their use with the Cypress cy.get() command:

Cheatsheet #1: Basic patterns

Image description

Cheatsheet #2: Advanced patterns

Image description

I really hope that this will be useful for you and help you improve your skills in testing. To continue your journey with me and get even more information about testing with the awesome Cypress tool, I invite you to subscribe to my blog “Testing with Cypress”.

Thank you for your attention! Happy testing!

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay