Home Java Overview Maven Tutorials

Tuesday, 23 January 2018

How to scroll browser in Selenium

Hello friends,

In this article we will discuss that how to perform scroll operation in selenium.

For Video :- Click Here

Watch Video for more Understanding

While automating an application we generally found that we need to perform here scroll Up or scroll down or Scroll up to an element, So in this demo we will learn that how to perform these all operations.

In selenium, we have JavascriptExecutor interface, to perform the scroll operation, which provide us a method "executeScript".

1). How to Scroll up :
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("window.scrollBy(0,-500)", "");

2). How to Scroll Down :
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("window.scrollBy(0, 500)", "");

3). How to Scroll Up to an element :
WebElement webelement = driver.findElement(By.xpath("xpath of your elements"));
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].scrollIntoView(true);", webelement);

4). How to Scroll up to bottom of webpage:
JavascriptExecutor js = (JavascriptExecutor) driver;

Below is the example that how to perform the above three operation in some realtime application :

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class Scroll_demo
WebDriver driver;
public void navigate() throws InterruptedException
System.setProperty("", "D:\\Selenium\\Complete selenium\\ChromeDriver\\chromedriver.exe");
driver=new ChromeDriver();
public void scrollTest()
WebElement link = driver.findElement(By.xpath(".//*[@id='post-body-751561208295527719']/div[1]/div[4]/div/table/tbody/tr[1]/td[1]/a"));
JavascriptExecutor jse = (JavascriptExecutor)driver;
//jse.executeScript("window.scrollBy(0,500)", "");
jse.executeScript("arguments[0].scrollIntoView(true);", link);;

Thanks :)

How to scroll in Appium: click here


  1. Really cool post, highly informative and professionally written and I am glad to be a visitor of this perfect blog, thank you for this rare info!

    software testing training in chennai

  2. This comment has been removed by the author.

  3. Wonderful post!!Thank you for sharing this info with us.
    Keep updating I would like to know more updates on this topic
    Very useful content, I would like to suggest this blog to my friends.

    Best selenium Training Institute in Chennai

    best selenium training in chennai

  4. I think this is the best article today. Thanks for taking your own time to discuss this topic, I feel happy about that curiosity has increased to learn more about this topic. Keep sharing your information regularly for my future reference.
    Software Testing Training in Chennai

  5. Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
    Web Design Training