Bird
0
0

Given this code:

medium📝 Predict Output Q5 of 15
Cypress - Selecting Elements
Given this code:
cy.get('[data-test="login"]')
  .type('user@example.com')
  .get('[data-test="password"]')
  .type('password123')

What is the issue with this code?
AThe code will type into both fields simultaneously
BThe selectors are invalid and will cause syntax errors
CThe type commands are missing parentheses
DThe second get command chains incorrectly from the first element
Step-by-Step Solution
Solution:
  1. Step 1: Analyze chaining behavior in Cypress

    When chaining commands, .get() after .type() searches within the yielded subject (the login field), not from the root.
  2. Step 2: Identify the problem

    The second .get incorrectly chains from the first element, attempting to find the password field inside the login field, causing failure.
  3. Final Answer:

    The second get command chains incorrectly from the first element -> Option D
  4. Quick Check:

    Separate cy.get calls start new queries [OK]
Quick Trick: Avoid chaining unrelated .get() commands; use separate statements [OK]
Common Mistakes:
  • Chaining multiple cy.get() commands for unrelated elements
  • Thinking selectors are invalid syntax
  • Believing type commands lack parentheses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes