Bird
0
0

What will the following Cypress code select?

medium📝 Predict Output Q4 of 15
Cypress - Selecting Elements
What will the following Cypress code select?
cy.get('.container').find('button.submit').should('be.visible')
AAll buttons with class 'submit' anywhere on the page
BAll visible buttons with class 'submit' inside elements with class 'container'
COnly the first button with class 'submit' inside '.container'
DAll elements with class 'container' that are buttons
Step-by-Step Solution
Solution:
  1. Step 1: Analyze selector chaining

    cy.get('.container') selects all elements with class 'container'. Then .find('button.submit') selects all buttons with class 'submit' inside those containers.
  2. Step 2: Understand assertion

    .should('be.visible') asserts these buttons are visible.
  3. Final Answer:

    All visible buttons with class 'submit' inside elements with class 'container' -> Option B
  4. Quick Check:

    Chained find selects nested visible buttons = All visible buttons with class 'submit' inside elements with class 'container' [OK]
Quick Trick: find() searches inside previous get() elements [OK]
Common Mistakes:
  • Thinking find() selects elements anywhere on page
  • Assuming only first matched element is selected
  • Confusing container class with button class

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes