user18119766
user18119766

Reputation:

Cypress and enumeration of properties

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.

Upvotes: 1

Views: 215

Answers (1)

Fody
Fody

Reputation: 32148

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
})

Upvotes: 1

Related Questions