I am learning selenium Webdriver. I was trying to take screenshot on chrome browser but I got exception for below code (Note: Same piece of code works on firefox). Kindly help me out to take a screenshot on Chrome and please somebody explain me why below code is not working on Chrome.
public class ScreenShot
{
public static void main(String[] args) throws IOException
{
String key = "webdriver.chrome.driver";
String value = "./driver/chromedriver.exe";
System.setProperty(key, value);
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.co.in");
TakesScreenshot screen = (TakesScreenshot) driver;
File srcFile = screen.getScreenshotAs(OutputType.FILE);
File destFile = new File("d:/google.png");
FileUtils.copyFile(srcFile, destFile);
}
}