Bird
0
0

Why might cy.scrollTo() fail to scroll an element even if the command is correct?

hard📝 Conceptual Q10 of 15
Cypress - Element Interactions
Why might cy.scrollTo() fail to scroll an element even if the command is correct?
AThe element must be visible before scrolling
BThe element is not scrollable or has no overflow
CThe command requires a callback function to work
Dcy.scrollTo() only works on the window, not elements
Step-by-Step Solution
Solution:
  1. Step 1: Understand scrollTo requirements

    scrollTo works only if the element is scrollable, meaning it has overflow and scrollbars.
  2. Step 2: Evaluate other options

    scrollTo works on elements, does not require callbacks, and can scroll even if element is not visible but scrollable.
  3. Final Answer:

    The element is not scrollable or has no overflow -> Option B
  4. Quick Check:

    Element must be scrollable for scrollTo to work [OK]
Quick Trick: Element must have overflow to be scrollable [OK]
Common Mistakes:
  • Thinking scrollTo only works on window
  • Expecting callback function
  • Assuming visibility is required

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes