Bird
0
0

Which of the following is the correct syntax to select the third element in a list using Cypress?

easy📝 Syntax Q12 of 15
Cypress - Selecting Elements
Which of the following is the correct syntax to select the third element in a list using Cypress?
Acy.get('li').eq(2)
Bcy.get('li').eq(3)
Ccy.get('li').first(3)
Dcy.get('li').last(3)
Step-by-Step Solution
Solution:
  1. Step 1: Recall zero-based indexing in eq()

    The eq() command uses zero-based index, so the third element is at index 2.
  2. Step 2: Check syntax correctness

    cy.get('li').eq(2) uses eq(2) correctly. Options A, C, and D either use wrong index or invalid syntax.
  3. Final Answer:

    cy.get('li').eq(2) -> Option A
  4. Quick Check:

    Third element index = 2 [OK]
Quick Trick: Remember eq() uses zero-based index, so third is eq(2) [OK]
Common Mistakes:
  • Using eq(3) for the third element
  • Trying to pass a number to first() or last()
  • Confusing eq() with first() or last()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes