最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Cypress filter selected ellements by severar included text - Stack Overflow

programmeradmin3浏览0评论

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

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')
Share Improve this question asked Sep 11, 2018 at 18:41 AtterratioAtterratio 4662 gold badges10 silver badges26 bronze badges 1
  • 1 Unclear. Can you please post example HTML with ments what exactly you wanna select? One element filtered by different text nodes that are nested within it, or several elements? – dwelle Commented Sep 12, 2018 at 8:13
Add a ment  | 

2 Answers 2

Reset to default 12

Use correct selector.

Ex:

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

Try this!

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.

发布评论

评论列表(0)

  1. 暂无评论