title: Current window screenshot using Selenium Webdriver in C#
body: <p>I am trying to take the screenshot of a test being executed in Selenium WebDriver in C#. I am using Gallio to run my tests. Below is my code for the screenshot:</p>
  
  <pre><code>public void TakeScreenshot(IWebDriver driver, string saveLocation)
  {
      ITakesScreenshot screenshotDriver = driver as ITakesScreenshot;
      Screenshot screenshot = screenshotDriver.GetScreenshot();
      screenshot.SaveAsFile(saveLocation, ImageFormat.Png);
  }
  </code></pre>
  
  <p>I am using the below code in my tests to take the screenshot:</p>
  
  <pre><code>IWebDriver driver = new ChromeDriver();
  TakeScreenshot(driver, @"C:\screenshot.png");
  </code></pre>
  
  <p>The problem is that while executing, the statement opens up a new chrome window and then pops up an error. My aim is to take the screenshot of an existing running script. What changes should I do to make this happen?</p>
  
  <p><strong>P.S. - Is there a way to take the screenshot while executing the test without initializing a new driver?</strong></p>