Taking screenshots

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: ...

Get Selenium WebDriver 3 Practical Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.