Bird
0
0

What is wrong with this Cypress selector?

medium📝 Debug Q6 of 15
Cypress - Selecting Elements
What is wrong with this Cypress selector?
cy.get('.button primary')
AIt will select elements with class 'button' or 'primary'
BIt tries to select an element with class 'button primary' but uses incorrect syntax
CIt correctly selects elements with both classes 'button' and 'primary'
DIt selects elements by id 'button primary'
Step-by-Step Solution
Solution:
  1. Step 1: Understand CSS class selector syntax

    Multiple classes must be concatenated with dots, no spaces: '.button.primary'
  2. Step 2: Identify the error

    Using a space selects descendant elements, so '.button primary' looks for 'primary' tag inside '.button' class, which is invalid here.
  3. Final Answer:

    It tries to select an element with class 'button primary' but uses incorrect syntax -> Option B
  4. Quick Check:

    Multiple classes need dot concatenation, no spaces [OK]
Quick Trick: Use .class1.class2 for multiple classes, no spaces [OK]
Common Mistakes:
  • Using space instead of dot between classes
  • Confusing class selectors with id selectors
  • Assuming space means 'or' in selectors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes