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...!!! Share on X

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...!!! Share on X

 

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

Other Useful References:

 

Author

  • Deepak Verma

    Deepak Verma is a Test Automation Consultant and Software development Engineer for more than 10 years. His mission is to help you become an In-demand full stack automation tester. He is also the founder of Techndeck, a blog and online coaching platform dedicated to helping you succeed with all the automation basics to advanced testing automation tricks.

    http://Techndeck.com deepak.rkgit@gmail.com Verma Deepak