Taking a screenshot of a web page is a very useful capability of WebDriver. This is very handy when your test case fails, and you want to see the state of the application when the test case failed. The TakesScreenShot interface in the WebDriver library is implemented by all of the different variants of WebDriver, such as Firefox Driver, Internet Explorer Driver, Chrome Driver, and so on.
The TakesScreenShot capability is enabled in all of the browsers by default. Because this is a read-only capability, a user cannot toggle it. Before we see a code example that uses this capability, we should look at an important method of the TakesScreenShot interface—getScreenshotAs().
The API syntax for getScreenshotAs() is as follows:
public X getScreenshotAs(OutputType target)
Here, OutputType is another interface of the WebDriver library. We can ask...