While working with Selenium in C#, I encountered an issue when trying to use the SaveAsFile
method with two parameters. Specifically, I wanted to pass ScreenshotImageFormat.png
” as the second parameter, but I kept getting a compile-time error.
Code snippet throwing the error:
screenshot.SaveAsFile(screenshotLocation, ScreenshotImageFormat.Png);
My whole method:
public string addScreenshot(IWebDriver driver, ScenarioContext scenarioContext)
{
ITakesScreenshot takesScreenshot = (ITakesScreenshot)driver;
Screenshot screenshot = takesScreenshot.GetScreenshot();
string screenshotLocation = Path.Combine(testResultPath, scenarioContext.ScenarioInfo.Title + ".Jpeg");
// this line is causing compile time error.
screenshot.SaveAsFile(screenshotLocation, ScreenshotImageFormat.Jpeg);
// this is working fine
screenshot.SaveAsFile("manas.png");
return screenshotLocation;
}