Taking ScreenShot Using Selenium WebDriver..!!

Here is the script to take the screenshot of the screen using Selenium webdriver.. Lets Automate it now.. 😀

import java.io.File;

import java.io.IOException;

import org.openqa.selenium.By;

import org.openqa.selenium.OutputType;

import org.openqa.selenium.TakesScreenshot;

import org.apache.commons.io.FileUtils;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.Test;

public class ScreenCaputreDemo

{

WebDriver driver;

@Test

public void OpenBrowser()

{

driver = new FirefoxDriver(); driver.get(“https://www.google.co.in/gfe_rd=cr&ei=tIQyVeRP6sjwB6zfgOAB&gws_rd=ssl”); driver.manage().window().maximize(); driver.findElement(By.id(“lst-ib”)).sendKeys(“selenium”);

Getscreenshot();

}

public void Getscreenshot()

{

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

try {

FileUtils.copyFile(scrFile, new File(“D:\\Google.jpg”));

} catch (IOException e)

{

e.printStackTrace();

}

}

}

Leave a comment