Bird
0
0

What will be the result of the following Selenium Java code snippet?

medium📝 Predict Output Q13 of 15
Selenium Java - JavaScriptExecutor
What will be the result of the following Selenium Java code snippet?
WebElement element = driver.findElement(By.id("footer"));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(false);", element);
System.out.println(element.isDisplayed());
Afalse
Btrue
CThrows NoSuchElementException
DThrows JavascriptException
Step-by-Step Solution
Solution:
  1. Step 1: Understand scrollIntoView(false) effect

    scrollIntoView(false) scrolls so element's bottom aligns with viewport bottom, making it visible.
  2. Step 2: Check element visibility after scrolling

    Since element is scrolled into view, element.isDisplayed() returns true.
  3. Final Answer:

    true -> Option B
  4. Quick Check:

    scrollIntoView(false) makes element visible = true [OK]
Quick Trick: scrollIntoView(false) scrolls element bottom into view [OK]
Common Mistakes:
  • Assuming isDisplayed() returns false after scrolling
  • Confusing scrollIntoView(true) and false
  • Expecting exceptions without missing element

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes