Scrolling a Web Page Up or Down using Selenium WebDriver
Posted By : Neha Dahiya | 07-Jun-2018
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