Do you need scroll the page ? (Selenium and javascript)

If you need scroll the page for example take a screenshot in a browser different of Firefox (Yes, the selenium have a problem to take a screenshot of the entire page when you are in a different browser like, IE)

So we have to create a function that take a screenshot of parts of the page, and this function helps you to scroll the page.

First you have to import the libraries:

import org.openqa.selenium.JavascriptExecutor;

 

After the code:

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(“window.scrollTo(0,Math.max(document.documentElement.scrollHeight,”
+ “document.body.scrollHeight,document.documentElement.clientHeight));”);

 

After this, the driver will scroll until the end of the current page.

I hope that I help you 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.