How can I take a screenshot with Selenium WebDriver?

James Hollingworth picture James Hollingworth · Aug 6, 2010 · Viewed 563k times · Source

Is it possible to take a screenshot using Selenium WebDriver?

(Note: Not Selenium Remote Control)

Answer

Sergii Pozharov picture Sergii Pozharov · Aug 6, 2010

Java

Yes, it is possible. The following example is in 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 somewhere
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));