πŸ’‘ If you like this website, please share it with your friends and network! πŸš€
Back to All Scenarios
Scenario 49 of 100
Scroll & Page
Beginner

Scrolling to the Bottom of the Page

⬇️Scenario Overview

Scrolling to the Bottom of the Page

Key Takeaways & Cheat Sheet

  • βœ“Utilize JavaScript Executor to dispatch window scroll operations
  • βœ“Set coordinates to scrollHeight to target bottom of page document
  • βœ“Ensure slow-loading components have time to render after scrolling
  • βœ“Avoid hardcoded coordinate bounds that vary by screen size

Short Direct Answer

To scroll directly to the bottom of the page, execute a JavaScript window scroll command using `JavascriptExecutor`. Instruct the browser to scroll down to the absolute `document.body.scrollHeight` of the active window context.

⚠️ Senior Warning (Red Flag)

Never use hardcoded pixel values (e.g. scrolling 2000 pixels) to scroll to the bottom of the page. Page heights vary dynamically based on browser window sizes and screen resolutions.

πŸ’‘ STAR Deep Dive Explanation & Pro Tip

This approach is highly reliable and automatically calculates the scroll limit dynamically, regardless of the browser height.

SeleniumAutomation.java
Selenium 4 + Java
// βœ… Scroll to bottom of the page
((JavascriptExecutor) driver).executeScript(
    "window.scrollTo(0, document.body.scrollHeight);"
);