cy.get('#list') selects the div containing the list.
Step 2: Find all li elements with class 'item' inside the div
.find('li.item') selects all three list items: Apple, Banana, Cherry.
Step 3: Get the length property
.its('length') returns the number of matched elements, which is 3.
Final Answer:
3 -> Option A
Quick Check:
3 list items found inside parent [OK]
Hint: Count matched children with .find() then .its('length') [OK]
Common Mistakes:
Assuming find returns only one element
Confusing .get() and .find() scopes
Expecting zero because of wrong selector
4. You wrote this Cypress code:
cy.get('.container').find('.button').click()
But the test fails with "Cannot read property 'click' of undefined". What is the likely cause?
medium
A. The selector '.button' does not exist inside '.container'
B. You should use cy.find() before cy.get()
C. You forgot to add .should('be.visible') before clicking
D. The .container selector is invalid syntax
Solution
Step 1: Understand the error message
"Cannot read property 'click' of undefined" means the element was not found, so click() fails.
Step 2: Check the selectors used
If '.button' does not exist inside '.container', then .find('.button') returns nothing, causing the error.
Final Answer:
The selector '.button' does not exist inside '.container' -> Option A
Quick Check:
Missing child element causes undefined click [OK]
Hint: Check if child selector exists inside parent before clicking [OK]
Common Mistakes:
Using find before get
Assuming visibility causes this error
Thinking selector syntax is wrong without checking
5. You want to test a list where each div.card contains a button.delete. How do you click the delete button only inside the second card using cy.find()?
hard
A. cy.find('div.card').eq(1).get('button.delete').click()
B. cy.get('div.card').find('button.delete').eq(1).click()
C. cy.get('button.delete').eq(1).click()
D. cy.get('div.card').eq(1).find('button.delete').click()
Solution
Step 1: Select the second card div
cy.get('div.card').eq(1) selects the second card (index 1).
Step 2: Find the delete button inside that card
.find('button.delete') searches only inside the selected card.
Step 3: Click the found button
.click() clicks the delete button inside the second card only.
Final Answer:
cy.get('div.card').eq(1).find('button.delete').click() -> Option D
Quick Check:
Get second card, then find button inside it [OK]
Hint: Select parent first with eq(), then find child inside it [OK]
Common Mistakes:
Using find before get
Selecting button globally then filtering
Using eq() after find instead of before
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.