Bird
0
0

What is the main reason to avoid using generic selectors like div or span in Cypress tests?

easy📝 Conceptual Q1 of 15
Cypress - Selecting Elements
What is the main reason to avoid using generic selectors like div or span in Cypress tests?
AThey improve test speed by selecting many elements at once
BThey can select multiple elements, causing unpredictable test behavior
CThey automatically wait for elements to appear
DThey are the recommended selectors for dynamic content
Step-by-Step Solution
Solution:
  1. Step 1: Understand generic selectors

    Selectors like div or span match many elements on the page.
  2. Step 2: Impact on test behavior

    Using such selectors can cause Cypress to interact with the wrong element or multiple elements, leading to flaky tests.
  3. Final Answer:

    They can select multiple elements, causing unpredictable test behavior -> Option B
  4. Quick Check:

    Generic selectors are too broad [OK]
Quick Trick: Avoid broad selectors to prevent flaky tests [OK]
Common Mistakes:
  • Assuming generic selectors target only one element
  • Believing generic selectors speed up tests
  • Thinking generic selectors handle dynamic content better

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes