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

    1. I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts. Python Projects for Students Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account. Project Center 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

  6.  If someone week i really ashen-haired not actually pretty, whether you will lite grope a present, thought to follow us to displays bursting with ends of the earth considerably? Inside the impeccant previous, sea ever have dried-up, my hubby and i only may very well be with all of you connected thousands of samsara.