Join 500+ Software Testing professionals. Solve problem and get your problem solved. Register Now!

0
how do i take a screenshot with Selenium WebDriver

Open 1 Answers 40 Views Selenium
0 1
I  need code in Java to take screenshot using selenium webdriver

1 Answer

0
0

You can try using below function.

 

public static String captureScreenshot(WebDriver driver,String screenshotdir) throws IOException {
String randomUUID = UUID.randomUUID().toString();
String storeFileName = screenshotdir + "\\"
+ getFileNameFromURL(driver.getCurrentUrl()) + "_"
+ randomUUID + ".png";
String[] screenshotdirsplit = screenshotdir.split("\\\\");
String fileName = screenshotdirsplit[screenshotdirsplit.length - 1] + "\\"
+ getFileNameFromURL(driver.getCurrentUrl()) + "_"
+ randomUUID + ".png";
File scrFile = ((TakesScreenshot) driver)
.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File(storeFileName));
return fileName;
}
 
answered by (327 points)
reshown by

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
...