contains() not working with filter and RegExp
See original GitHub issueCurrent behavior
The .contains() command currently only works when split into .get() and .contains() with Regular Expression.
Desired behavior
I’d like to use a single command to search for an element with a regular expression. The RegExp is needed to distinguish “edit & save” and “edit” f.e. without using an index. The single .contains()
also works, when including the final html tag the text is within like so: main .container p
Test code to reproduce
it('on cypress website', () => {
cy.visit('https://www.cypress.io/');
cy.get('main .container').contains(new RegExp('^Cypress is the new standard in front-end testing that every developer and QA engineer needs.$', 'm'));
});
works but this doesn’t:
it.only('on cypress', () => {
cy.visit('https://www.cypress.io/');
cy.contains('main .container', new RegExp('^Cypress is the new standard in front-end testing that every developer and QA engineer needs.$', 'm'));
})
Cypress Version
8.7.0
Other
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Regular expression to match a line that doesn't contain a word
The notion that regex doesn't support inverse matching is not entirely true. You can mimic this behavior by using negative look-arounds: ^((?!hede).)*$.
Read more >Regular expressions for customizing and filtering alerts
Learn how to use regular expressions when filtering in Opsgenie and view sample definitions.
Read more >Spark rlike() Working with Regex Matching Examples
Use regex expression with rlike() to filter rows by checking case insensitive (ignore case) and to filter rows that have only numeric/digits ...
Read more >using regexp in where filter on an property not defined in the ...
Query with regex filter on properties not defined in model should work.
Read more >Use regular expressions in filters and automated rules
When you set up filters or automated rules, you use pattern matching to specify ... such as "Show campaigns that contain ' -...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Maw-Jung, thanks for your reproducible code. I’ve been able to to recreate this in cypress 9.2.0.
additionally this test case works as expected
The Contains code is located here: https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/commands/querying.ts#L447
@sainthkh no worries, i wasn’t in time, either. The problem occurs with the generated tree, which i have no control over. Thus i can only identify reoccuring elements by content further down the node. I’ll try to add an simplified example:
ul> li> span>banana</span /li> li> span>pineapple</span /li> /ul>
I hope this makes it a bit more clear, i need to grab the li-elements by identifying the correct one by it’s content. This example clearly lacks all the boilerplate dom around the described nodes, but i think it works as an example.cy.contains('ul li', new RegExp('^pineapple$', 'm'));
What i want this to find is the element containing ‘pineapple’ within the subtree of ‘ul li’ to achieve a better performance with big trees. Thanks for your response, hope this makes it any clearer.