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);"
);