I have written a simple selenium script to capture screenshot and for some reason, this script is throwing the exception:
java.io.IOException: The filename, directory name, or volume label syntax is incorrect
public class ScreenshotUtil {
WebDriver driver;
public ScreenshotUtil(WebDriver driver) {
this.driver = driver;
}
public String getScreenShot(String fileName) {
SimpleDateFormat dFormat = new SimpleDateFormat("dd-MM-yyy HH-mm-ss");
Date date = new Date();
dFormat.format(date);
TakesScreenshot ts = (TakesScreenshot) driver;
File source = ts.getScreenshotAs(OutputType.FILE);
String path = "./Screenshots/" + fileName + "_" + date + ".png";
File destination = new File(path);
try {
FileUtils.copyFile(source, destination);
} catch (Exception e) {
e.printStackTrace();
}
return path;
}
}