Atterratio
Atterratio

Reputation: 466

Cypress filter selected ellements by severar included text

I have a select query of several lines something like this:

cy.get('#test-container').find('.row')

I want to find one, that contains some text (for example 'test title' and 'test value') in different subellements together. Or at least test that this row exist. Something like this:

cy.get('#test-container').find('.row').filter('include.text', 'test title').filter('include.text', 'test value')

Upvotes: 7

Views: 12475

Answers (2)

Mateus Moura
Mateus Moura

Reputation: 344

Use correct selector.

Ex:

cy
  .get('#test-container')
  .find('.row')
  .filter(':contains("test title")')

Try this!

Upvotes: 12

Craig
Craig

Reputation: 348

Cypress filter takes a selector as its parameter, it does not appear to match on text content of the DOM element.

Instead, you could use cy.contains with a regular expression.

cy.get('#test-container').find('.row').contains(/(?:test title|test value)/)

The parentheses and question mark is to indicate a non-capturing group, which matches on any of the items on either side of the pipe. MDN RegEx docs give more info.

Upvotes: 1

Related Questions