How to scroll down a webpage in selenium using Java?

0 votes
I have a webpage open using selenium and now I want to scroll down. How can I get it done?

Please help.
Dec 17, 2018 in Selenium by Anjali
• 2,950 points
25,720 views

3 answers to this question.

0 votes

Hello @User,

In order to scroll the web page you can use JavascriptExecutor. 

Create an object for JavascriptExecutor and call the webdriver. Then execute the script with a scrollTo function and using that you can either scroll to a particular section or to the bottom of your page.

Here is the script for doing this:

JavascriptExecutor js = ((JavascriptExecutor) driver);
js.executeScript("window.scrollTo(0, document.body.scrollHeight)");
Thread.sleep(5000);

We are using thread.sleep to give the browser a time to scroll if you have used driver.close(); then the browser may close before scroll takes place and you may not see the result.

answered Dec 17, 2018 by Nabarupa
ALWAYS put in doubt any solution that includes Thread.sleep()
0 votes
This works...

JavascriptExecutor jse = (JavascriptExecutor)driver;

jse.executeScript("scroll(0, 500);");
answered Apr 3, 2019 by anonymous
0 votes
JavascriptExecutor js = ((JavascriptExecutor) driver);
js.executeScript("window.scrollTo(0, document.body.scrollHeight)");


or 
js.executeScript("arguments[0].scrollIntoView(true);", element);


or 


//scroll to x y 
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollBy("x","y")");
answered Sep 3 by Sri
• 2,970 points

Related Questions In Selenium

0 votes
2 answers

How to scroll the Page up or down in Selenium WebDriver? (using java)

JavascriptExecutor jsx = (JavascriptExecutor)driver; jsx.executeScript("window.scrollBy(0,555)", ""); or Action classes ...READ MORE

answered Sep 5 in Selenium by Sri
• 2,970 points
13,546 views
+1 vote
2 answers

Is it possible to scroll down in a webpage using selenium webdriver programmed on python?

I using next code for facebook for ...READ MORE

answered May 16, 2019 in Selenium by mslavikas@gmail.com
18,710 views
0 votes
1 answer

How to scroll up/down a page using Actions class in Selenium?

Hi Naetik, you can use Actions class ...READ MORE

answered Jul 4, 2019 in Selenium by Anvi
• 14,110 points
8,652 views
0 votes
1 answer

How to wait for the webpage to load in selenium using java

Firstly, when you launch a web application, ...READ MORE

answered Aug 28, 2018 in Selenium by bug_seeker
• 15,510 points
639 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,520 points
3,783 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31 in Selenium by Sri
• 2,970 points
4,766 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
2,742 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2 in Selenium by Sri
• 2,970 points
3,109 views
0 votes
1 answer

How to get the HTML source of a webpage using Selenium in Java?

There is a method called getPageSource() in ...READ MORE

answered Jan 10, 2019 in Selenium by Sneha
12,513 views
+1 vote
2 answers

How to get the title of a webpage using Selenium Java?

Essentially, driver.getTitle(); function can be used to ...READ MORE

answered Dec 17, 2018 in Selenium by Vardhan
• 13,180 points
7,292 views