How to take screenshot using Selenium WebDriver

By | May 14, 2019

Taking screenshot using selenium is simple and it helps us to debug the failure and to find out the root cause. By looking at screenshot, we can get to know the details why and at which step test has failed.

TakesScreenShot interface is used to achieve this task and this TakesScreenShot capability is enabled by default in most of the browsers.

In the below example, web page is having the link with name ‘Third Link and it doesn’t have link with name “Fourth Link“. Here script is trying to verify, whether link is present or not in the UI.

Screenshot using selenium:



Third Link is present.
Fourth Link is not present in the UI.
PASSED: selenium99_Screenshot

Analysis: ‘Third link’ exists in the web page so “Third Link is present” will be printed on the console. ‘Fourth Link’ doesn’t exist on the page so the execution goes to catch block and there it calls the takeScreenshot() method. It takes path as a parameter and saves the screenshot in this location. In this example, you have learned taking screenshot using selenium webdriver.

Other Topics:


Mouse hover events in Selenium WebDriver


Tags: selenium webdriver, selenium, screenshot in selenium, selenium screenshot, webdriver, selenium automation testing, screenshot using selenium, selenium training, selenium online training, selenium qa testing, selenium automation tool, selenium testing, selenium qa testing, selenium tutorials

Leave a Reply

Your email address will not be published. Required fields are marked *