Bird
0
0

You wrote this Cypress test:

medium📝 Debug Q14 of 15
Cypress - Selecting Elements
You wrote this Cypress test:
cy.get('[data-cy=submit]').click()

But the test fails with "Cannot find element" error. What is the most likely cause?
AThe <code>click()</code> method is not supported on buttons.
BThe element does not have a <code>data-cy='submit'</code> attribute.
CThe selector syntax is incorrect; it should be <code>cy.get('data-cy=submit')</code>.
DCypress cannot click elements inside forms.
Step-by-Step Solution
Solution:
  1. Step 1: Check the selector correctness

    The selector [data-cy=submit] is correct syntax for attribute selection.
  2. Step 2: Identify why element is not found

    If the test fails to find the element, it likely means the element does not have the data-cy='submit' attribute in the HTML.
  3. Final Answer:

    The element does not have a data-cy='submit' attribute. -> Option B
  4. Quick Check:

    Missing attribute = The element does not have a data-cy='submit' attribute. [OK]
Quick Trick: Check if attribute exists on element first [OK]
Common Mistakes:
  • Blaming click() method for failure
  • Using wrong selector syntax
  • Assuming Cypress can't click form elements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes