Bird
0
0

Given the HTML:

medium📝 Predict Output Q4 of 15
Cypress - Selecting Elements
Given the HTML:
<div class='container'>
  <button class='btn primary'>Submit</button>
  <button class='btn secondary'>Cancel</button>
</div>

What will cy.get('.btn.primary').should('contain', 'Submit') check?
AIt checks if any button with class 'btn' contains 'Submit'
BIt checks if any element with class 'primary' contains 'Submit'
CIt checks if the button with both classes 'btn' and 'primary' contains 'Submit'
DIt checks if the container div contains 'Submit'
Step-by-Step Solution
Solution:
  1. Step 1: Understand combined class selector

    .btn.primary selects elements with both classes 'btn' and 'primary'.

  2. Step 2: Match with HTML structure

    The first button has both classes and text 'Submit', so the assertion checks that button's text.

  3. Final Answer:

    It checks if the button with both classes 'btn' and 'primary' contains 'Submit' -> Option C
  4. Quick Check:

    Combined classes select elements with all classes [OK]
Quick Trick: Use dot without space to combine classes [OK]
Common Mistakes:
  • Using space between classes selects descendants
  • Assuming single class match
  • Confusing container with button

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes