Bird
0
0

What will happen if you run:

medium📝 Predict Output Q5 of 15
Cypress - Element Interactions
What will happen if you run:
cy.scrollTo('left');
cy.get('#header').should('be.visible');
on a page with no horizontal scroll?
AThe page stays at left edge and #header visibility is checked
BThe test throws an error because no horizontal scroll exists
CThe page scrolls vertically instead
DThe test fails because 'left' is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Understand scrollTo behavior with no scroll

    If no horizontal scroll exists, scrolling to 'left' keeps the page at the left edge without error.
  2. Step 2: Check assertion behavior

    The test then checks if '#header' is visible, which proceeds normally.
  3. Final Answer:

    The page stays at left edge and #header visibility is checked -> Option A
  4. Quick Check:

    scrollTo left with no scroll = no error [OK]
Quick Trick: scrollTo on non-scrollable axis does nothing, no error [OK]
Common Mistakes:
  • Expecting error on no scroll
  • Thinking scrollTo scrolls vertically when given 'left'
  • Using invalid keywords

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes