Scroll Page in Selenium:

 

What is a scrollbar?

  • A scrollbar is one that lets you move around the screen in a horizontal or vertical direction if the current page is not fit in the viewing area of the scrolling screen.
  • It is used to move the window up and down.
  • Selenium Webdriver does not require scrolling to work because it combines DOM. But in some web pages, users only appear once, when users scroll them down scrolling in such cases may be necessary.
  • The scroll bar has two types: horizontal and vertical scroll bars.

 

Multiple Ways to Scroll Down and Scroll Up page:

  1. Scroll Down and Scroll Up page using JavascriptExecutor.
  2. Scroll Down and Scroll Up page using Robot Class.
  3. Scroll Down and Scroll Up page Using Actions Class.

  

1. Scroll Down and Scroll Up page using JavascriptExecutor:

  • Using JavascriptExecutor we can Scroll up and Scroll Down Web Page.
  • Using window.scrollBy(0,250) OR scroll(0, 250) Methods we can Scroll Page.

 

Package:

Create JavascriptExecutor class object:

 Scroll Down:

Scroll Up:

 

Example of Scroll Page in Selenium with JavaScriptExecutor class: 

 

2. Scroll Down and Scroll Up page using Robot Class:

  • Using Robot Class we can Scroll up and Scroll Down Web Page.
  • Using keyPress(KeyEvent.VK_PAGE_DOWN) Method we can Scroll Page.

 

Package:

Create Robot class object:

 Scroll Down:

 Scroll Up:

 

Example of Scroll Page using Robot class:

 

3. Scroll Down and Scroll Up page Using Actions Class: 

  • Using Actions Class we can Scroll up and Scroll Down Web Page.
  • Using keyDown(Keys.CONTROL).sendKeys(Keys.END) Method we can Scroll Page.

 

Package:

Create Action class object:

Scroll Down:

Scroll Up:

 

Example to Scroll Using Actions class:

How to Scroll Down or UP a Page in Selenium Webdriver and Vertical Scroll down and scroll up in Selenium WebDriver with java and How to scroll the Page up or down in Selenium WebDriver