Part 9: Usages Of Javascripts In Selenium: How To Scroll Page By Page In Selenium WebDriver Using Javascript

Hello Folks,

In last post, we have learnt to scroll a web page by pixels. In this post, we will see how to scroll a web page , page by page.

What is page in Web page?

Follow below steps:

  1. Open browser and load url “http://www.makeseleniumeasy.com/“.
  2. Wait till page is loaded.
  3. Now press Key “Page Down” and notice how much page is scrolled down. You have scrolled web page by a page.
  4. If you keep pressing “Page Down” key, you will reach bottom of page.

The same we can achieve using javascript in selenium webdriver.

Java code:

  1. First we need to get page height of one page.
  2. Then we need to get how much is scroll-able height. Generally it will be “Height of a page* No of pages”.
  3. Now get number of pages. It will be number of times of pressing “Page Down” key to get bottom of page.

Java Code:

Output:
When you run the program, you will notice page is scrolled down page by page till it reaches to bottom of the web page.

That’s it guys in this post. We will see some more interesting thing about scroll in up coming posts.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
#ThanksForReading
#HappySelenium

Leave a Reply

Your email address will not be published. Required fields are marked *