1

In Cypress, is it possible to assert that any one of a number of elements matches a specific rule?

For example, something like this:

cy.get('nav').children().any.should('have.value', 'My value');
half of a glazier
  • 1,864
  • 2
  • 15
  • 45

1 Answers1

0

It's simpler than I thought...

cy.get('nav').contains('div', 'My value');

This will get the nav element and assert that it contains a div tag with the text My value.

Thanks to @JoshuaWade for this solution in his answer to How to get data displaying in a table in Cypress.io test?

half of a glazier
  • 1,864
  • 2
  • 15
  • 45
  • This does not work for me. I need to check the value of an element and if I try `cy.get('[data-testid="my-input"]').should('have.value', 'the value')` it fails if there are multiple ones when the first one does not have the expected value. In other words Cypress doesn't check all the elements, just the first one. – theberzi May 23 '22 at 12:07