title: Is it possible to programmatically take a screenshot while the computer is locked?
body: <p>I am running Selenium testing overnight (using Java &amp; WebDriver) and would like to take a screenshot when one of the testcases fails. If I use the Robot's <code>createScreenCapture()</code> method it only works if the monitor is on, and if I use the Selenium's <code>getScreenshotAs()</code> method it doesn't capture any popups or anything that are on top of the window (and often contain the cause of the problem). The <code>getScreenshotAs()</code> method does work when the pc is locked so that is what I am currently using. My machines run Windows 7 if that matters.</p>
  
  <p>I adapted this code (found on this site) and am using this currently:</p>
  
  <pre><code>WebDriver driver = new FirefoxDriver();
  driver.get("http://www.google.com/");
  File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
  // Now you can do whatever you need to do with it, for example copy somewhere
  FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));
  </code></pre>
  
  <p>This is what I had used previously but it only captures a grey screen with the task bar at the bottom if the pc is locked, but if I'm logged in it works great and captures everything. The problem is I need to have my computer locked overnight and that is when this code needs to run:</p>
  
  <pre><code>Robot robot = new Robot();
  // Get size of screen
  Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
  // Capture the screen
  BufferedImage screenFullImage = robot.createScreenCapture(screenRect);
  // Save the screen to to disk
  ImageIO.write(screenFullImage, "jpg", new File(fileName));
  </code></pre>
  
  <p>I found some other posts on here asking similar questions but they were all pretty old and didn't quite match my question so I was wondering if any solution given these circumstances was possible?</p>
  
  <hr>
  
  <p><strong>EDIT:</strong>
  When I use the Robot code these are the results. I tried using both Chrome as the browser (ChromeDriver) and Firefox (FirefoxDriver).</p>
  
  <p><strong>Chrome:</strong>
  <a href="https://i.stack.imgur.com/8Z83H.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8Z83H.jpg" alt="Screenshot Using Google Chrome"></a></p>
  
  <p><strong>Firefox:</strong>
  <a href="https://i.stack.imgur.com/gbPCu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gbPCu.png" alt="enter image description here"></a></p>
  
  <p>If I run the Robot version of the screen capture in a class all by itself, just a loop that captures the screen every 5 seconds (Run As > Java Application), it works just fine even with the computer locked, but when I have Selenium run the same code (its Run As > JUnit Test) when a test fails it gives the screenshots above if the pc is locked. I even tried having the Selenium code spawn a new thread to take the screenshot while it did a <code>Thread.sleep()</code> but got the same results once the pc was locked. </p>