Following code will help to take the screenshot entire page of any webpage.
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class TakeScreenshot {
static WebDriver driver;
// Browser startup
@BeforeClass
public void setup() {
driver = new FirefoxDriver();
}
@Test
public void gomezTest() throws InterruptedException, IOException {
// Capturing Screen shot
driver.get("http://www.google.com");
//Get entire page screenshot
try
{
File screenshotFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
//Copy the element screenshot to disk
FileUtils.copyFile(screenshotFile, new File("\\GoogleLogo_screenshot.png"));
}
catch(Exception e)
{
e.printStackTrace();
}
}
@AfterClass
public void tear() {
driver.close();
}
}
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class TakeScreenshot {
static WebDriver driver;
// Browser startup
@BeforeClass
public void setup() {
driver = new FirefoxDriver();
}
@Test
public void gomezTest() throws InterruptedException, IOException {
// Capturing Screen shot
driver.get("http://www.google.com");
//Get entire page screenshot
try
{
File screenshotFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
//Copy the element screenshot to disk
FileUtils.copyFile(screenshotFile, new File("\\GoogleLogo_screenshot.png"));
}
catch(Exception e)
{
e.printStackTrace();
}
}
@AfterClass
public void tear() {
driver.close();
}
}