Bird
0
0

Consider this code:

medium📝 Predict Output Q5 of 15
Selenium Java - JavaScriptExecutor
Consider this code:
WebElement element = driver.findElement(By.cssSelector(".menu-item"));
((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView();", element);
What is the default alignment of the element after scrolling?
AElement aligned at the bottom of the viewport
BElement aligned at the top of the viewport
CElement centered in the viewport
DNo scrolling occurs
Step-by-Step Solution
Solution:
  1. Step 1: Know default scrollIntoView behavior

    Without parameters, scrollIntoView aligns element at the top.
  2. Step 2: Apply to given code

    Code calls scrollIntoView() without arguments, so element aligns top.
  3. Final Answer:

    Element aligned at the top of the viewport -> Option B
  4. Quick Check:

    Default scrollIntoView() aligns top [OK]
Quick Trick: Default scrollIntoView() aligns element top [OK]
Common Mistakes:
  • Assuming default aligns bottom
  • Thinking element is centered
  • Believing no scroll happens

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes