1

This code is in a loop to get a screenshot, however I get a blank screen, since a new window opens each time.

How do I minimize the new window so get a screen capture of the background window?

static string TakeScreenshot(string _getScreenShotName)
        {

        try
        {
            IWebDriver driver = new InternetExplorerDriver(@"C:\myCSharp\mySelenium\mySelenium\");
            Screenshot sss = ((ITakesScreenshot)driver).GetScreenshot();
            sss.SaveAsFile(string.Format("{0}_{1:yyyy-MM-dd_HH-mm-ss}.jpeg", _getScreenShotName, DateTime.Now), System.Drawing.Imaging.ImageFormat.Gif);
            System.Console.WriteLine(_getScreenShotName);
            return _getScreenShotName;
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
            throw;
        }
       }
Miss QA
  • 55
  • 6
  • 2
    What are you trying to achieve? You're not doing anything with the IEDriver you're using to get the screenshot, that's why it's blank. If by "background window" you mean the desktop, don't use IEDriver's screenshot engine to take a screenshot. – Pierre-Luc Pineault Jan 19 '15 at 23:14

2 Answers2

1

You should use

//this will maximize the browser and also helps you to set focus on actual browser not on IEDriverServer exe
IWebDriver driver = new InternetExplorerDriver(@"C:\myCSharp\mySelenium\mySelenium\");
driver.Navigate().GoToUrl("some url");
driver.Manage().Window.Maximize();

Unfortunately, there is currently no way to minimize the browser if you want that to do unless using native C# mechanism.

Refer to this

Saifur
  • 15,084
  • 6
  • 43
  • 68
  • 1
    I had to change the script to include the screenshot capture since I could not minimize the window. Thank you for your help. – Miss QA Jan 20 '15 at 19:26
1

As 'Pierre-Luc Pineault' has already mentioned in the comment,

Use the driver to navigate to a site first before taking the screenshot (as given below).

IWebDriver driver = new InternetExplorerDriver(@"C:\myCSharp\mySelenium\mySelenium\");
driver.get("http://www.google.com");
Screenshot sss = ((ITakesScreenshot)driver).GetScreenshot();
sss.SaveAsFile(string.Format("{0}_{1:yyyy-MM-dd_HH-mm-ss}.jpeg", _getScreenShotName, DateTime.Now), System.Drawing.Imaging.ImageFormat.Gif);
System.Console.WriteLine(_getScreenShotName);
return _getScreenShotName;

You can not use the driver's GetScreenshot method to take the desktop screenshot. If that is what you want to do, please refer to this answer

Community
  • 1
  • 1
vins
  • 13,336
  • 2
  • 29
  • 42