Skip to content

Instantly share code, notes, and snippets.

@timothyshort
Last active January 12, 2024 13:28
Show Gist options
  • Save timothyshort/49228727983e6ed5c7c92e8f5fb04602 to your computer and use it in GitHub Desktop.
Save timothyshort/49228727983e6ed5c7c92e8f5fb04602 to your computer and use it in GitHub Desktop.
Take a screenshot of Selenium WebDriver
// This method takes a screenshot of the browser and saves as a file
public static void snap(WebDriver driver, String filename) {
String rootFolder = "C:/Users/SeleniumProjects/TestOutput/";
File ScreenshotFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); // Create file from the screenshot of driver
try {
FileUtils.copyFile(ScreenshotFile, new File (rootFolder + filename + ".jpg"));
} catch (IOException e) {
System.out.println("Could not save the file");
e.printStackTrace();
}
}
@nusratkhowaja
Copy link

getting error msg
The method copyFile(File, File) is undefined for the type FileUtils

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment