Free Source Code and Tutorials

Custom Search

How to take screenshots in Selenium?

In this post we will learn how to take Screenshot in Selenium WebDriver.

Taking screenshot during automated run is very important. It is useful in reporting and for better look and feel of the reports.

Below is the code for taking Screenshot:

  1. import;
  2. import;
  4. import org.openqa.selenium.OutputType;
  5. import org.openqa.selenium.TakesScreenshot;
  6. import org.openqa.selenium.WebDriver;
  7. import org.openqa.selenium.remote.Augmenter;
  8. import org.openqa.selenium.remote.DesiredCapabilities;
  9. import org.openqa.selenium.remote.RemoteWebDriver;
  11. public class Testing {
  13. public void screenshotDemo() throws Exception {
  14. WebDriver driver = new RemoteWebDriver(
  15. new URL("http://localhost:4444/wd/hub"),
  16. DesiredCapabilities.firefox());
  18. driver.get("");
  20. // RemoteWebDriver does not implement the TakesScreenshot class
  21. // if the driver does have the Capabilities to take a screenshot
  22. // then Augmenter will add the TakesScreenshot methods to the instance
  23. WebDriver augmentedDriver = new Augmenter().augment(driver);
  24. File screenshot = ((TakesScreenshot)augmentedDriver).
  25. getScreenshotAs(OutputType.FILE);
  26. }
  27. }
Facebook Comments
(Visited 4 times, 2 visits today)
Share this

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked * © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!

%d bloggers like this: