I have a use case wherein there's a div element on the webpage, it appears like a popup dialog as soon as you click a link (its not an actual popup, its something like dialog boxes which opens in Facebook when you click a link to check reactions on your posts etc.)
I'm using Selenium WebDriver with Java to automate tests for this application, my use case involves me to scroll to the bottom of the dialog box where there is a link to show more items, when user clicks show more, it populates another 10 items in the list and so on until there are no other items left for the user to visit.
So basically I have to scroll down on that particular div element till I keep seeing Show More
link and when driver is not able to find show more link it should stop.
Note - I can't just scroll to bottom of the page using javascript window.scrollTo()
as it will scroll down through whole webpage, however I just want to scroll to bottom of that division element only.
If anybody have any idea on how to achieve this please let me know.
Thanks for the help in advance !
scroll_Page(scrollArea ,100);
For vertical scrollable bar use the x and y axis. Set the overflow-x:hidden; and overflow-y:auto; that will automatically hide the horizontal scroll bar and present only vertical scrollbar. Here the scroll div will be vertically scrollable.
Scenario 1: To scroll down the web page by pixel. Javascript method ScrollBy() scrolls the web page to the specific number of pixels. The syntax of ScrollBy() methods is : executeScript("window. scrollBy(x-pixels,y-pixels)");
The JavaScriptExecutor provides an interface that enables QAs to run JavaScript methods from Selenium scripts. Hence, to scroll up or down with Selenium, a JavaScriptExecutor is a must. The scrollBy() method involves two parameters, x, and y, that represent the horizontal and vertical pixel values, respectively.
Another way of scrolling to the bottom inside (of) any scroll-able element:
public void scrollToBottomInsideDiv(WebElement scrollArea) {
JavascriptExecutor js = ((JavascriptExecutor) webdriver);
js.executeScript("arguments[0].scrollTo(0, arguments[0].scrollHeight)", scrollArea);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With