How to take Screenshot using Selenium WebDriver?

package pkg_selenium;

import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

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;

public class TakeScreenShot {
public static WebDriver driver;

public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub

// Initialize WebDriver

driver = new FirefoxDriver();

// Wait For Page To Load

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

// Go to URL

driver.get("https://developer.paypal.com/");

// Maximize Window
driver.manage().window().maximize();

// Take ScreenShot

File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);


FileUtils.copyFile(scrFile, new File("D:\\selenium\\screenshot1.png"), true);

// Close Driver

driver.quit();


}

}

Comments

Popular posts from this blog

Encoding and Decoding in Selenium using Base64 Class of Java

Parallel Execution In TestNG Framework Using ThreadLocal Concept

How to handle calendar or date picker using dynamic XPATH?