Back to All Scenarios
Scenario 52 of 100
Scroll & Page
Advanced
Scrolling Internally Inside a Scrollable Container Div
βοΈScenario Overview
Scrolling Internally Inside a Scrollable Container Div
Key Takeaways & Cheat Sheet
- βIdentify target container element with overflow-y scroll style
- βModify target element scrollTop property using JavascriptExecutor
- βAvoid global window scroll commands which are ignored by divs
- βVerify internal content elements have loaded after scroll
Short Direct Answer
To scroll inside a container with overflow styling (like a terms-and-conditions box or dynamic side-panel), you must target the scrollable div directly. Use JavaScript to set the div's `scrollTop` property to its `scrollHeight`.
β οΈ Senior Warning (Red Flag)
Do not use standard window.scrollTo() on internal scrollable panels. Internal divs ignore global window scroll events, resulting in no page movement and click failures.
π‘ STAR Deep Dive Explanation & Pro Tip
Updating the scrollTop property directly triggers the container's internal scroll event, instantly rendering elements hidden below the visible panel fold.
SeleniumAutomation.java
Selenium 4 + Java// β
Locate the internal scrollable container div
WebElement scrollContainer = driver.findElement(By.className("terms-scroll-panel"));
// β
Scroll container internally to its bottom limit
((JavascriptExecutor) driver).executeScript(
"arguments[0].scrollTop = arguments[0].scrollHeight;",
scrollContainer
);