How to Scroll Web Page in Selenium

Let’s see, How can you scroll web page in Selenium.  In Selenium, We can scroll down the page using javascript executor.

Some websites especially e-commerce website, More products will be displayed only If scroll down the page. Same thing on facebook website. More posts will be loaded only If you scroll down the page. In this kind of scenario, You can use javascript executor to scroll down page If you want to take some action on page element which appears on scroll down.

 

Scroll Web Page in Selenium

Scroll by given pixel offset

I have created the test script to scroll down-up web page In horizontal or vertical direction based on given x y pixel offset.
Bellow given example will first scroll down(X direction) web page by 600 pixels and then It will scroll up It by 300 pixels.

 

Scroll to element In selenium WebDriver

If you want to scroll till some element on the page then you can use element parameter In javascript as shown In below example.

0 Comment

Leave a Reply