Posted by Neha Dahiya | Last Updated: 28-Jun-18
Let’s look at different scenarios to scroll down using Selenium WebDriver:
- To scroll down the web page by pixel
- ?To scroll down the web page by
visibilityof the element?
- To scroll at the bottom of the web page
To scroll down the web page by pixel:
Find the Script to scroll down the web page by pixel below
Description: In the above code, the page is scrolled by 1000 pixels using the executeScript. ScrollBy() method is used to scroll the page to the specified number of pixels.
ScrollBy() methods is used as follows :
If number is positive X-pixels moves to the left and if negative moves to the right.
If number is positive y-pixels moves downwards and if number is negative moves in downward direction.
For example: js.executeScript("window.scrollBy(0,1000)");
This will scroll down vertically down by 1000 pixels
To scroll down the web page by the visibility of the element.
Find the below Script to scroll down the web page by visibility of the element
Where arguments is first index of the page and “Element ” is locator on the page.
To scroll down the web page at the bottom of the page
Find the below Script to scroll down the web page at the bottom