'how to take full page screenshot in chrome using selenium

In selenium tool, how to take full page screenshot and how to scroll the page? If we use this code,

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

it directly move to the bottom of the page.



Solution 1:[1]

System.setProperty("webdriver.chrome.driver", "F:\\chromedriver.exe"); 

ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(options);   
String baseUrl = "https://www.google.co.in";

driver.get(baseUrl);        
String fullscreen =Keys.chord(Keys.F11);
driver.findElement(By.cssSelector("body")).sendKeys(fullscreen);

TakesScreenshot scrShot =((TakesScreenshot)driver);  
File SrcFile=scrShot.getScreenshotAs(OutputType.FILE);   
File DestFile=new File("F://test.png");  
FileUtils.copyFile(SrcFile, DestFile);   
driver.close();

Solution 2:[2]

For this, we need to download the ashot.jar file and add to the project along with the 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 TakeFullPageScreenShot
{
   public static void main(String args[]) throws Exception
   {
       System.setProperty("webdriver.gecko.driver",     "D:\\Selenium\\geckodriver.exe");
   WebDriver driver = new FirefoxDriver();

   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 to the end and captures the screenshot. And we can control the scroll speed using the viewportPasting method.

hope that helps

Solution 3:[3]

Use the jar file of shutterbug in selenium. Here you can download the file : http://book2s.com/java/jar/s/selenium-shutterbug/download-selenium-shutterbug-0.4.html

And here is the command that will be placed in your code:

Shutterbug.shootPage(driver, ScrollStrategy.BOTH_DIRECTIONS).save("path to save image");

You dont need to handle any scrolls this is going to automatically capture full page screenshot

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jatin gangwani
Solution 2 Saurabh Verma
Solution 3 Rabia Asif