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,930 points
7,465 views

2 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
0 votes
This works...

JavascriptExecutor jse = (JavascriptExecutor)driver;

jse.executeScript("scroll(0, 500);");
answered Apr 3 by anonymous

Related Questions In Selenium

0 votes
1 answer

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

Its pretty simple. Check out the below ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,430 points
9,011 views
+1 vote
2 answers
0 votes
1 answer
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,360 points
257 views
0 votes
1 answer

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,430 points
1,198 views
0 votes
1 answer
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,510 points
1,281 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,510 points
1,039 views
0 votes
1 answer
+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
• 12,870 points
845 views