Bharat Mane Bharat Mane - 1 month ago 19
Java Question

How to take multiple ScreenShots in Selenium at different time intervals?

By using below script, I am taking only one Screenshot every time, which it overrides on the same screenshot.

What should I do If I want to take different screenshots at some small time of interval?

public void screenShot() throws IOException, InterruptedException
File scr=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

File dest= new File("filPath/1.png");
FileUtils.copyFile(scr, dest);


Just use the current time to name your files, this example names the files after the current minutes and hours values (of course you may use seconds, milliseconds, days, whatever..) :

Calendar calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);

String directory = "filPath";
String fileName = "snapshot_"+ hour + "_"+ minute +".png";

File dest = new File(directory, fileName);