Challenge - 5 Problems
cy.contains() Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What does this cy.contains() command select?
Given the HTML below, what element will
cy.contains('Submit') select?Cypress
<button>Submit</button> <button>Submit Form</button> <div>Submit</div>
Attempts:
2 left
💡 Hint
cy.contains() finds the first element that contains the text anywhere inside it.
✗ Incorrect
cy.contains() finds the first element in the DOM that contains the given text, not necessarily an exact match. It stops at the first match.
❓ assertion
intermediate2:00remaining
Which assertion correctly checks that an element contains the text 'Welcome'?
You want to verify that a
contains the text 'Welcome'. Which assertion is correct?
Cypress
cy.get('div').contains('Welcome')
Attempts:
2 left
💡 Hint
Use the correct Cypress assertion for partial text matching.
✗ Incorrect
contain.text checks if the element's text includes the given substring. have.text requires exact match.
❓ locator
advanced2:00remaining
Which cy.contains() usage finds a button with exact text 'Cancel' only?
You want to find a
Attempts:
2 left
💡 Hint
Use a regular expression to match exact text in cy.contains().
✗ Incorrect
Passing a regex /^Cancel$/ to cy.contains() matches exact text only. Option A matches partial text.
🔧 Debug
advanced2:00remaining
Why does this cy.contains() command fail to find the text?
Given the HTML:
<span>Click here</span>, why does cy.contains('click here') fail?Cypress
cy.contains('click here')Attempts:
2 left
💡 Hint
Check text case sensitivity in cy.contains().
✗ Incorrect
cy.contains() matches text case-sensitively by default, so 'click here' does not match 'Click here'.
❓ framework
expert2:00remaining
How to chain cy.contains() to find a child element with specific text inside a parent?
You want to find a
with class 'card' that contains a
with text 'Hello'. Which command correctly finds the
inside the card?
Attempts:
2 left
💡 Hint
Use cy.contains() with selector to find child element inside parent.
✗ Incorrect
cy.get('div.card').contains('p', 'Hello') finds a
inside the
but then filters text, which may fail if multiple
exist.