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
• 11,380 points
1,819 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
• 11,380 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
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, 2020 in Selenium by Sri
• 3,050 points
15,150 views
+1 vote
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,460 points
1,972 views
0 votes
8 answers

How to open a link in new tab of chrome browser using Selenium WebDriver?

This below code works for me in ...READ MORE

answered Dec 13, 2020 in Selenium by Gitika
• 65,910 points
69,858 views
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, 2019 in Selenium by anonymous

edited May 2, 2019 by Omkar 759 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
5,306 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,050 points
5,989 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
3,708 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, 2020 in Selenium by Sri
• 3,050 points
4,496 views