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
44,632 views

5 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. For further understanding, you can refer to the Selenium Certification.

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, 2020 by Sri
• 3,190 points
0 votes

You can use the down arrow to scroll down on a web page and the up arrow to scroll back up. Here's how: First, use your mouse to click anywhere on the page you'd like to read; this lets the computer know where you are reading. Then, tap the down arrow just once to scroll down a little bit at a time.

answered Dec 16, 2020 by Gitika
• 65,770 points
0 votes

 to scroll up or down with Selenium, a JavaScript executor is a must. Scroll functions can be defined as follows : JavascriptExecutor js = (JavascriptExecutor) driver; js. executeScript("window.J

answered Dec 16, 2020 by Roshni
• 10,480 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 6, 2020 in Selenium by Sri
• 3,190 points
18,908 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
26,072 views
0 votes
1 answer

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

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

answered Jul 5, 2019 in Selenium by Anvi
• 14,150 points
20,590 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 29, 2018 in Selenium by bug_seeker
• 15,510 points
1,932 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,500 points
13,672 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

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

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,142 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,910 points
7,221 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 3, 2020 in Selenium by Sri
• 3,190 points
7,874 views
+1 vote
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 11, 2019 in Selenium by Sneha
29,480 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,150 points
15,919 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP