Bird
0
0

You wrote this Cypress test:

medium📝 Debug Q14 of 15
Cypress - Selecting Elements
You wrote this Cypress test:
cy.get('#login').click()

But the test fails with 'Cannot read property click of undefined'. What is the likely cause?
AThe element with ID 'login' does not exist on the page.
BThe click() command is misspelled.
Ccy.get() cannot select elements by ID.
DThe test needs a wait() before click().
Step-by-Step Solution
Solution:
  1. Step 1: Understand error meaning

    'Cannot read property click of undefined' means cy.get() did not find the element, returning undefined.
  2. Step 2: Check element existence

    If the element with ID 'login' is missing or not loaded, cy.get('#login') fails to find it.
  3. Final Answer:

    The element with ID 'login' does not exist on the page. -> Option A
  4. Quick Check:

    Missing element causes undefined and click error [OK]
Quick Trick: Check if element exists before clicking [OK]
Common Mistakes:
  • Assuming syntax error causes this
  • Thinking cy.get() can't select by ID
  • Adding wait() without verifying element presence

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes