xxxxxxxxxx
// Full page Screenshot
((TakesScreenshot) driver).getScreenshotAs(OutuputType.file)
// Element Screenshot
((TakesScreenshot) element).getScreenshotAs(OutputType.file)
xxxxxxxxxx
//create object of TakesScreenshot Interface with webdriver type
TakesScreenshot ts = (TakesScreenshot)webdriver;
//call a method of TakeScreenShot Interface to capture img
File SrcFile = ts.getScreenshotAs(OutputType.FILE);
//now we just have make copy of it to store
File destination = new File(pathOfFile);
//use
FileUtils.copy(SrcFile, destination);
//or this
FileHandler.copy(srcFile, destination);
xxxxxxxxxx
Java
Yes, it is possible. The following example is in Java:
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com/");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// Now you can do whatever you need to do with it, for example copy somewhere
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));
xxxxxxxxxx
spark = SparkSession.builder.getOrCreate();
spark.sparkContext().setLogLevel("OFF");