Take screenshot of the options in dropdown in selenium c#.

We can take screenshots of the options in dropdown with Selenium Webdriver. A screenshot is generally captured for the failure test cases. This is achieved with the help of ITakesScreenshot interface.

We shall take the help of GetScreenshot method to grab the screenshot. Finally, the SaveAsFile method is used where we pass the parameters – the path of the file and format of the image.



For implementation we shall be using the NUnit framework.


using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using System;
namespace NUnitTestProject1{
   public class Tests{
      String u ="https://www.tutorialspoint.com/selenium/selenium_automation_practice.htm";
      IWebDriver d;
      public void Setup(){
         //creating object of FirefoxDriver
         d = new FirefoxDriver();
      public void Test1(){
         //identify dropdown
         IWebElement l = d.FindElement(By.Name("continents"));
         //scroll to dropdown
         .ExecuteScript("arguments[0].scrollIntoView(true);", l);
         //capture screenshot along file name
         .GetScreenshot().SaveAsFile("Screenshot.png", ScreenshotImageFormat.Png);
      public void close_Browser(){


Right−click on the project in Solution Explorer. Then click on Open Folder in File Explorer.

Then move to folder bin−>Debug, the file named Screenshot.png should be available.