cy.get("h2").contains("My page") doesn't work. Other methods yes!
See original GitHub issueCurrent behavior:
The first method doesn’t work at all! Never. And I don’t understand why from the docs.
Desired behavior:
I think the 4 methods below are the same, right? I also read this: https://github.com/cypress-io/cypress/issues/1805
Steps to reproduce:
- cy.get("h2").contains("My page"); // Doesn't work! Never! Why?
- cy.get("#root > div > div > div.col-md-10 > div > div.d-flex > h2").contains("My page"); // Works!
- cy.contains("h2", "My page"); // Works!
- cy.get("h2").should("contain", "My page"); // Works!
Versions
- Cypress 3.0.1
- Chrome 67
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
contains - Cypress Documentation
Get the DOM element containing the text. DOM elements can contain more than the desired text and still match. Additionally, Cypress prefers some...
Read more >Using Cypress - Cypress Documentation
Cypress offers you many robust ways to query the DOM, all wrapped with retry-and-timeout logic. Other ways to wait for an element's presence...
Read more >get | Cypress Documentation
Get one or more DOM elements by selector or alias. The querying behavior of this command is similar to how $(...) works in...
Read more >Best Practices - Cypress Documentation
If the answer is yes because the word Submit is critical and should not be changed - then use cy.contains() to target the...
Read more >Cypress - Code Like This
Sometimes the built-in assertions are enough, but often you need to test the page's contents in other ways. Cypress's should method lets you...
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
Unfortunately is not on the public internet!
And it is a mess to reproduce exactly it.
But the question is why every time (100 times!) the methods are working and the first one no!?
Unfortunately we have to close this issue as there is not enough information to reproduce the problem.
Please comment in this issue with a reproducible example and we will reopen the issue. 🙏