Bird
0
0

What will be the result of the following Cypress code?

medium📝 Predict Output Q5 of 15
Cypress - Selecting Elements
What will be the result of the following Cypress code?
cy.get('button').eq(1).should('have.text', 'Submit')

Assuming the buttons are:
<button>Cancel</button>
<button>Submit</button>
<button>Reset</button>
ATest passes because second button text is 'Submit'
BTest fails because eq(1) selects first button
CTest fails because button text is 'Cancel'
DTest throws syntax error
Step-by-Step Solution
Solution:
  1. Step 1: Identify element selected by eq(1)

    Using zero-based indexing, eq(1) selects the second button, which has text 'Submit'.
  2. Step 2: Check assertion correctness

    The assertion checks if the selected button has text 'Submit', which is true, so the test passes.
  3. Final Answer:

    Test passes because second button text is 'Submit' -> Option A
  4. Quick Check:

    cy.eq(1) = second element, text 'Submit' [OK]
Quick Trick: Remember eq() uses zero-based index to select elements [OK]
Common Mistakes:
  • Assuming eq(1) selects first element
  • Confusing button order
  • Expecting syntax error from correct code

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes