How to take screenshot of a Web page using Selenium WebDriver in Java

Selenium is one of the most popular automation testing framework and has the capability to capture screenshot of a web page. It runs on all major browsers. So, in this particular example, we are going to use Google Chrome. As it can be used in various programming languages like Ruby, Python, Java etc. Hence, In this post, we are going to use it to learn how to take a web page screenshot in JAVA?”.

Capture_Screenshot_Web_Page_Java_Selenium_Webdriver_FeaturedImage_Techndeck

Take a Web page screenshot in Java using Selenium Webdriver...!!! Click To Tweet

In this tutorial, we are going to cover below topics:

  1. Configure Selenium Webdriver and other required dependencies in the project

  2. How to take a screenshot of a web page in Java?

 

Let’s begin:

1. Add required dependencies into the Project

As we are using Selenium Webdriver, there we first need to configure it into our project either by downloading the Selenium Java Jar file and add it into the classpath or specify the below maven dependency into your maven project.

Also, add below supported dependencies

 

2. Capture Web Page Screenshot in Java

 

Let’s try to understand the code:

1. Set up the Chrome Driver

 

2. Specify the targeted URL and access it through the driver object

 

3. Capture screenshot with the help of TakesScreenshot Webdriver Interface and save it

 

Take a Web page screenshot in Java using Selenium Webdriver...!!! Click To Tweet

 

Do you like this Post? – then check my other helpful posts:

Other Useful References:

 

Related Posts:

[wcp-carousel id=”5342″]

 

2 thoughts on “How to take screenshot of a Web page using Selenium WebDriver in Java

Leave a Reply

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

Facebook Twitter Instagram YouTube