How to take screenshot in Selenium WebDriver

By | April 19, 2020

Taking screenshot in 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.

Take screenshot in selenium:

 

Output:

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.

Conclusion:

In this article, you have learned how to take screenshot in selenium. 

Recommended Posts:

TestNG

Mouse hover events in Selenium WebDriver

 

Tags: Take screenshot in selenium, selenium webdriver, selenium, screenshot in selenium, selenium screenshot, selenium automation testing, screenshot using selenium. Take screenshot in 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 *