Cypress and enumeration of properties

Viewed 27

Good day everyone! I can't seem to find the answer in the cypress documentation. I may be looking at it wrong.

The task is the following - I have some number of identical elements (eg 4) that are scattered across the page. They have a common class. I need to place all 4 elements in a loop so that the set of commands is executed in turn for each element. How to do it?

P.S . - They are not in the same list or even container. They only have the same class and name which will allow them to be collected.

1 Answers

You would be looking for .each() command

cy.get('.common-class').each($el => {
  cy.wrap($el)...  // this is equivalent to cy.get() one of the elements
})
Related