Please try with this full method to take screenshot and store the results in particular path. It is working for me. Try with this and let me know.
public void TakeScreenShots(String TestID,String ResultsPath){
try{
GlobalVariable.bExitTestIteration = false;
if(!(TestID.length()>0)){
System.out.println("chk");
}
if((TestID.length()>0) && (ResultsPath.length()>0)){
TestID=//DriverScript.sScenarioID;
ResultsPath="//DriverScript.ResultsFolder";
//****** Check if local variable is used **********
if (ResultsPath.length()>2){
if (ResultsPath.substring(0, 1)=="%%"){
ResultsPath = getDictinaryValues(ResultsPath.substring(2));
}
}
//*************************************************
Log.info("Take a screenshot ");
WebDriverWait wait = new WebDriverWait(driver, 10);
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(ResultsPath+"\\" +TestID+ ".png"));
}
}catch(Exception e){
Log.error("Not able to take a screenshot --- " + e.getMessage());
}
}
Please check this piece of code and respond to me.