Unable to take the screenshot of the entire page in chrome using webdriver

0 votes

How to take the screenshot of the full page and how to scroll the page with this code:

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

This directly moves to the end of the page.

Mar 26, 2018 in Selenium by nitinrawat895
• 10,710 points
686 views

1 answer to this question.

+1 vote

I solved this issue myself actually. I downloaded the ashot.jar file first and added it to the project along with other Selenium JAR files

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import ru.yandex.qatools.ashot.AShot;
import ru.yandex.qatools.ashot.Screenshot;
import ru.yandex.qatools.ashot.shooting.ShootingStrategies;
import javax.imageio.ImageIO;
import java.io.File;

public class PageScreenShot
{
   public static void main(String args[]) throws Exception
   {
 System.setProperty("webdriver.gecko.driver","D:\\Selenium\\geckodriver.exe");
      WebDriver driver = new ChromeDriver();
    driver.get("http://automationtesting.in/");
    Thread.sleep(2000);
    Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver);
  ImageIO.write(screenshot.getImage(),"PNG",new                              
File(System.getProperty("user.dir") +"/ErrorScreenshots/FullPageScreenshot.png"));
   }
}

It will scroll the page down to the very end and capture the screenshot. And we can control the scroll speed using the viewportPasting method. :)

answered Mar 26, 2018 by nitinrawat895
• 10,710 points
Hi Nitin, thanks for the answer, that actually worked for me. I am Upvoting your answer as it is a very clear and explained.

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,110 points
8,415 views
0 votes
2 answers
0 votes
1 answer

How to take screenshot of a frame using Selenium WebDriver?

you can use the below code: import java.awt.image.BufferedImage; import ...READ MORE

answered Jun 20, 2018 in Selenium by Meci Matt
• 9,420 points
792 views
0 votes
5 answers
0 votes
0 answers

Unable to pass url in firefox and chrome by using selenium webdriver

Hi All, I am not able to run ...READ MORE

May 1 in Selenium by anonymous

edited May 2 by Omkar 294 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,110 points
956 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,130 points
1,124 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,130 points
862 views