Screenshot In Selenium Using C#

Its very important to take screenshot when we execute a test script. When we execute huge number of test scripts, and if some test fails, we need to check why the test has failed.
It helps us to debug and identify the problem by seeing the screen shot.

In selenium WebDriver, we can take the screen shot using the below command:

SaveScreenShotClass.SaveScreenshot(Driver, “FileName”);

Check the framework example of taking screenshots:

class SaveScreenShotClass
public static string SaveScreenshot(IWebDriver driver, string ScreenShotFileName) // Definition
var folderLocation = (“Path to save the Screenshots”);

if (!System.IO.Directory.Exists(folderLocation))

var screenShot = ((ITakesScreenshot)driver).GetScreenshot();
var fileName = new StringBuilder(folderLocation);

screenShot.SaveAsFile(fileName.ToString(), System.Drawing.Imaging.ImageFormat.Jpeg);
return fileName.ToString();

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s