Is it possible to take a screenshot using Selenium WebDriver?

Is it possible to take a screenshot using Selenium WebDriver?

Hello Tom-dale,

Yes, please refer to the following code snippet for Java:

WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com/");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
//

Now you can do whatever you need to do with it, for example, copy it somewhere:

FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));