Challenge - 5 Problems
Cypress cy.find() Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of nested cy.find() commands
What will be the output of the following Cypress test code snippet when it runs successfully?
Cypress
cy.get('.parent').find('.child').should('have.length', 2); cy.get('.parent').find('.child').eq(0).should('contain.text', 'First');
Attempts:
2 left
💡 Hint
Remember that cy.get() selects elements globally, and .find() searches within those elements.
✗ Incorrect
cy.get('.parent') selects the parent element(s). Then .find('.child') searches only inside those parents. The test expects exactly 2 child elements and the first child's text to be 'First'.
❓ assertion
intermediate1:30remaining
Correct assertion for element found by cy.find()
Which assertion correctly verifies that a button inside a form with class '.login' is disabled using cy.find()?
Attempts:
2 left
💡 Hint
Use cy.get() to select the parent, then .find() to locate the child element inside it.
✗ Incorrect
Option C correctly selects the form with class '.login' and then finds the button inside it, asserting it is disabled. Option C is invalid because cy.find() is not a global command. Option C reverses parent and child. Option C uses a combined selector but does not use .find().
🔧 Debug
advanced2:30remaining
Why does this cy.find() command fail?
Given the code below, why does the test fail to find the '.item' elements inside '.container'?
Cypress
cy.get('.container').find('.item').should('have.length', 3); // HTML structure: // <div class="container"> // <div class="wrapper"> // <div class="item">One</div> // <div class="item">Two</div> // </div> // <div class="item">Three</div> // </div>
Attempts:
2 left
💡 Hint
Remember that .find() searches all descendants, not just direct children.
✗ Incorrect
The .find() command searches all descendants, so it should find all three .item elements inside .container, including nested ones. If the test fails, it is likely due to a selector or timing issue, not because .find() misses nested elements.
❓ framework
advanced2:00remaining
Best practice for chaining cy.find() in Cypress tests
Which option describes the best practice when using cy.find() inside Cypress tests to locate elements within a parent?
Attempts:
2 left
💡 Hint
Think about test stability and scope when selecting elements.
✗ Incorrect
Using cy.get() to select a parent element and then chaining .find() to locate children scopes the search and reduces the chance of selecting wrong elements, improving test reliability.
🧠 Conceptual
expert3:00remaining
Understanding cy.find() behavior with multiple parents
If cy.get('.list') selects multiple elements, what will cy.get('.list').find('.item') return?
Attempts:
2 left
💡 Hint
Consider how Cypress commands handle multiple elements and chaining.
✗ Incorrect
cy.get('.list') can select multiple elements. When .find('.item') is chained, it searches inside each matched .list element and returns all matching .item elements combined.