Challenge - 5 Problems
Cypress Selector Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
What element does cy.first() select?
Given the following HTML:
And this Cypress code:
What text will the command yield?
<ul> <li>Apple</li> <li>Banana</li> <li>Cherry</li> </ul>
And this Cypress code:
cy.get('li').first().invoke('text')What text will the command yield?
Cypress
cy.get('li').first().invoke('text')
Attempts:
2 left
💡 Hint
cy.first() selects the very first element from the matched set.
✗ Incorrect
cy.first() picks the first element from the list of matched elements. Here, the first <li> contains 'Apple'.
❓ Predict Output
intermediate1:30remaining
What element does cy.last() select?
Given the same HTML:
And this Cypress code:
What text will the command yield?
<ul> <li>Apple</li> <li>Banana</li> <li>Cherry</li> </ul>
And this Cypress code:
cy.get('li').last().invoke('text')What text will the command yield?
Cypress
cy.get('li').last().invoke('text')
Attempts:
2 left
💡 Hint
cy.last() picks the last element from the matched set.
✗ Incorrect
cy.last() selects the last <li> element, which contains 'Cherry'.
❓ Predict Output
advanced1:30remaining
What element does cy.eq(1) select?
Given the same HTML:
And this Cypress code:
What text will the command yield?
<ul> <li>Apple</li> <li>Banana</li> <li>Cherry</li> </ul>
And this Cypress code:
cy.get('li').eq(1).invoke('text')What text will the command yield?
Cypress
cy.get('li').eq(1).invoke('text')
Attempts:
2 left
💡 Hint
cy.eq(index) selects the element at the zero-based index.
✗ Incorrect
cy.eq(1) selects the second element (index 1) which contains 'Banana'.
❓ assertion
advanced1:30remaining
Which assertion correctly checks the text of the first item?
You want to check that the first <li> element contains the text 'Apple'. Which Cypress assertion is correct?
Cypress
cy.get('li').first()
Attempts:
2 left
💡 Hint
Use 'have.text' to check exact text content.
✗ Incorrect
'have.text' checks the exact text inside the element. 'contain.text' checks if text is included. 'have.value' is for input values. 'have.html' checks inner HTML.
🧠 Conceptual
expert2:00remaining
Why use cy.eq() instead of cy.first() or cy.last()?
Which statement best explains when to use cy.eq(index) over cy.first() or cy.last()?
Attempts:
2 left
💡 Hint
Think about selecting elements by position.
✗ Incorrect
cy.eq(index) lets you pick any element by its zero-based index. cy.first() and cy.last() only pick the first or last element.