TestProject Forum
Powered by leading experts in the test automation community

Take screenshot with selenium in java

How can I take screenshots in the middle of my test runs with selenium?

Does selenium have a built-in function for that ?

Hi,
You can take screenshots with the following code and copy it to your local drive:

[code]WebDriver driver = new ChromeDriver();

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

FileUtils.copyFile(ssFile, new File(“C:\screenshot.png”));[/code]

Oh I didn’t know its possible to specify the screenshot to an element. That’s neat.

Thanks for the help again !