Bird
0
0

You need to scroll a page to the bottom using JavaScriptExecutor in Selenium Java. Which code snippet correctly handles this edge case?

hard📝 Application Q8 of 15
Selenium Java - JavaScriptExecutor
You need to scroll a page to the bottom using JavaScriptExecutor in Selenium Java. Which code snippet correctly handles this edge case?
Ajs.executeScript("window.scrollTo(0, document.body.scrollHeight);");
Bjs.executeScript("window.scrollBy(0, 1000);");
Cjs.executeScript("scrollToBottom();");
Djs.executeScript("document.body.scrollTop = document.body.scrollHeight;");
Step-by-Step Solution
Solution:
  1. Step 1: Understand scrolling to bottom with JavaScript

    window.scrollTo(0, document.body.scrollHeight) scrolls to the bottom of the page.
  2. Step 2: Evaluate other options

    scrollBy scrolls by fixed pixels, scrollToBottom is not a standard function, and setting scrollTop on body may not work in all browsers.
  3. Final Answer:

    js.executeScript("window.scrollTo(0, document.body.scrollHeight);"); -> Option A
  4. Quick Check:

    Use window.scrollTo with scrollHeight to reach bottom [OK]
Quick Trick: Use window.scrollTo with scrollHeight for full page scroll [OK]
Common Mistakes:
  • Using non-standard JS functions
  • Scrolling by fixed pixels instead of full height
  • Setting scrollTop on wrong element

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes