Bird
0
0

What is wrong with this code snippet?

medium📝 Debug Q7 of 15
Cypress - Selecting Elements
What is wrong with this code snippet?
cy.get('#nav').find('.link').click()

Given that there are multiple elements with class link inside #nav.
Aclick() will fail because multiple elements are found without specifying which one.
Bfind() cannot select elements by class.
Cget() should be replaced with find() here.
DThe selector '#nav' is invalid.
Step-by-Step Solution
Solution:
  1. Step 1: Understand find() returns multiple elements

    find('.link') returns all matching descendants inside #nav.
  2. Step 2: Clicking multiple elements causes error

    click() expects a single element; multiple matches cause failure.
  3. Final Answer:

    click() will fail because multiple elements are found without specifying which one. -> Option A
  4. Quick Check:

    click() requires single element [OK]
Quick Trick: Use .first() or .eq() before click() if multiple elements found [OK]
Common Mistakes:
  • Assuming click() works on multiple elements
  • Confusing get() and find() usage
  • Ignoring selector validity

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes