question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cy.get("h2").contains("My page") doesn't work. Other methods yes!

See original GitHub issue

Current 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:closed
  • Created 5 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ghostcommented, Jun 21, 2018

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!?

0reactions
jennifer-shehanecommented, Apr 24, 2019

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. 🙏

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found