Selenium Webdriver Appium Complete TutorialSelenium Webdriver Appium Complete Tutorial
Automation Testing
  • Tools
    • Selenium
      • Selenium Java Tutorial
      • Selenium C# Tutorial
    • Appium
      • Appium Java Tutorial
      • Appium C#Tutorial
    • Katalon
  • Trainings
  • TestNG
  • Reports
    • Extent Reports
      • Extent Reports – Java
      • Extent Reports – Java -Version3
      • Extent Reports – C#
    • Vigo Reports
    • AT Excel Report
  • Excel
    • Apache POI – Java
    • Excel With C#
  • Interview Questions
    • Selenium Interview Questions
    • Java Interview Questions
    • C# Interview Questions
  • Demo Site
  • Practice Site
  • More…
    • AutoIt
    • Sikuli
    • Robot Class
    • File Upload
    • ScreenShot
      • AShot
      • ShutterBug
  • About
January 20, 2017

Taking Full Page Screenshot in Selenium





Taking full page screenshot in selenium will discuss about how to take full page screenshot image in selenium webdriver while automating any application. As already we know how to take screenshot in selenium webdriver. But the actual issue is, when we take screenshot how much area will it capture. Here we need to discuss 2 things that how the methods which are available with Selenium webdriver will behave in Selenium 2 and Selenium 3 as recently selenium 3 is launched.

As already we know that in selenium 2; no extra drivers needed to launch the FirefoxDriver but for other browsers we need to use driver exe files to launch and work with. While working with the FirefoxDriver and try to take the screenshot then it will capture the entire page including the invisible area of the web page. But if you use other browsers then it will capture only the visible area of the webpage.

But coming to the Selenium 3, to launch any browser we need to use the driver exe files. So, while capturing the screenshot in selenium 3 it will capture only the visible area of the web page in all the browsers including firefox. To overcome this we can use third party utility called AShot. It is a WebDriver screenshot utility and by using this we can capture the entire page screenshot and can capture the individual webelement screenshot also.

For this, we need to download the ashot.jar file and add to the project along with the selenium jar files. We can download the ashot.jar file from here.




Below is the sample code to capture the entire page screenshot for any browser:

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("https://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"));
   }
}

In the above program 20,21 lines will do the magic. It will scroll the page till the end and captures the screenshot. And we can control the scroll speed using viewportPasting method.

This way we can capture the entire page screenshot using ashot.jar file.

Please watch the youtube video for better understanding.



Share this post: on Twitter on Facebook

File Upload using Robot Class in Selenium Taking Web Element Screenshot in Selenium

Related Posts

Image Comparison in Selenium

AShot

Image Comparison in Selenium

TAKING WEB ELEMENT SCREENSHOT IN SELENIUM

AShot

Taking Web Element Screenshot in Selenium

Newsletter

Recent Posts

  • TAKING WEB ELEMENT SCREENSHOT IN SELENIUMHow to Capture WebElement Screenshot in Selenium Webdriver using selenium 4
    December 15, 2019
  • How To SWAP Two Numbers in Java Without using Temp VariableHow to SWAP Two Numbers in Java Without Temp variable or Without Third variable
    December 8, 2019
  • How to Swap Two Numbers in Java with Temp VariableHow to SWAP Two Numbers in Java using Temp Variable
    December 1, 2019
  • How to Read Properties file in JavaHow to Read Data From Properties File in Java
    November 27, 2019
  • Compare two arrays in java with out inbuilt functionsHow to Compare Two Arrays in Java without built-in functions
    November 16, 2019
© Selenium Webdriver Appium Complete Tutorial 2025