Bird
0
0

What will happen if you use cy.get('.btn-primary').click() but the class btn-primary changes to btn-main in the app?

medium📝 Predict Output Q5 of 15
Cypress - Selecting Elements
What will happen if you use cy.get('.btn-primary').click() but the class btn-primary changes to btn-main in the app?
AThe test will pass because Cypress auto-updates selectors
BThe test will fail because the selector no longer matches
CThe test will click a different element with a similar class
DThe test will ignore the click and continue
Step-by-Step Solution
Solution:
  1. Step 1: Understand selector dependency

    Selectors based on class names break if the class changes in the app.
  2. Step 2: Evaluate Cypress behavior

    Cypress does not auto-update selectors; it relies on exact matches.
  3. Final Answer:

    The test will fail because the selector no longer matches -> Option B
  4. Quick Check:

    Selector breakage = A [OK]
Quick Trick: Avoid selectors tied to styling classes [OK]
Common Mistakes:
  • Assuming Cypress fixes broken selectors automatically
  • Using unstable selectors that change often
  • Ignoring test failures caused by selector changes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes