Selenium – How to take a screenshot with Selenium WebDriver


Is it possible to take a screenshot using Selenium WebDriver?

(Note: Not Selenium Remote Control)

Best Solution


Yes, it is possible. The following example is in Java:

WebDriver driver = new FirefoxDriver();
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"));