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.
Snippet giving me 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 giving me compile time error.
screenshot.SaveAsFile(screenshotLocation, ScreenshotImageFormat.Jpeg);
//this is working fine
screenshot.SaveAsFile("manas.png");
return screenshotLocation;
}