Cypress: Single and multicriteria selections


Introduction

This post contains a list of combinations of selection commands involving single and multiple criteria. The command examples often do a little bit more than selecting an element but the main thing is the selection, the rest is just to give some ideas in which context that selection command could be used for example. The table of contents above is written in a way to help to find the interesting combination quickly. I will keep adding new combinations to this post because Cypress allows so many different ways to combine selection criteria.

By id

Example with #;

cy.get(‘#someElementId’);

Exampe with id attribute:

cy.get(‘[id*=SomePartOfId’);

By id, element, element, index

 Example with cy.get and >:

cy.get(‘#someElementId > tbody > tr‘).eq(2).should(‘be.visible’);

By element, class, content

Example with one cy.get():

cy.get(‘span.SomeClass:contains(“SomeText“)’).closest(‘.classX .classY’);