0
0
Cypresstesting~20 mins

cy.contains() for text matching in Cypress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
cy.contains() Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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>
AAll elements containing the text 'Submit'
BThe first element containing the text 'Submit'
CThe first <button> with exact text 'Submit'
DOnly the <div> with text 'Submit'
Attempts:
2 left
💡 Hint
cy.contains() finds the first element that contains the text anywhere inside it.
assertion
intermediate
2: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')
Acy.get('div').should('include.text', 'Welcome')
Bcy.get('div').should('have.text', 'Welcome')
Ccy.get('div').should('contain.text', 'Welcome')
Dcy.get('div').should('contain', 'Welcome')
Attempts:
2 left
💡 Hint
Use the correct Cypress assertion for partial text matching.
locator
advanced
2:00remaining
Which cy.contains() usage finds a button with exact text 'Cancel' only?
You want to find a
Acy.contains('button', /^Cancel$/)
Bcy.get('button').contains('Cancel')
Ccy.contains('button', 'Cancel')
Dcy.get('button').should('have.text', 'Cancel')
Attempts:
2 left
💡 Hint
Use a regular expression to match exact text in cy.contains().
🔧 Debug
advanced
2: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')
Acy.contains() is case-sensitive and 'click here' does not match 'Click here'
Bcy.contains() only matches exact text, so partial text fails
Ccy.contains() requires a selector argument before the text
DThe element is not visible, so cy.contains() cannot find it
Attempts:
2 left
💡 Hint
Check text case sensitivity in cy.contains().
framework
expert
2: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?

Acy.get('div.card p').contains('Hello')
Bcy.contains('div.card').contains('p', 'Hello')
Ccy.get('div.card').contains('p', 'Hello')
Dcy.get('div.card').find('p').contains('Hello')
Attempts:
2 left
💡 Hint
Use cy.contains() with selector to find child element inside parent.