Capturing Screenshot into PDF File using Selenium


                                     
Capturing Screenshot into PDF File using Selenium



In this blog, we are going to learn how we can capture screenshot of any web page while executing selenium automation scripts and store it in PDF file.

For this purpose, we would be using Java inbuilt libraries along with iTextPDF Jar which provides the facility to capture the screenshot and save them in PDF files.


To start with we need to add below maven dependency or Jar. We can also download them from the Maven Repository using link.


In the code, we have following the below sequence:


v  Capturing the screenshot and store it in byte[] array format.
v  Initiate and open PDF writer.
v  Process and set the size of the image
v  Add Image to PDF and close the File.

Below is the detailed code snippet for capturing screenshot of Google homepage and storing it in PDF File.

Result of the above code execution would be 




Happy Learning :)




SHARE THIS

Author:

My Name is Ankur Jain and I am currently working as Automation Test Architect.I am ISTQB Certified Test Manager,Certified UI Path RPA Developer as well as Certified Scrum Master with total 12 years of working experience with lot of big banking clients around the globe.I love to Design Automation Testing Frameworks with Selenium,Appium,Protractor,Cucumber,Rest-Assured, Katalon Studio and currently exploring lot in Dev-OPS as well. I am currently staying in Mumbai, Maharashtra. Please Connect with me through Contact Us page of this website.

Previous Post
Next Post
August 15, 2019 at 5:03 PM

I have bookmarked your website because this site contains valuable information in it. I am really happy with articles quality and presentation. Thanks a lot for keeping great stuff. I am very much thankful for this site.
search text in pdf

Reply
avatar
March 11, 2020 at 10:21 AM

I believe you have observed some very interesting points, appreciate it for the post. anyconv.com

Reply
avatar
April 10, 2020 at 11:52 AM

Exceptional entry! I found it very interesting. I'll check back later to see if more posts are added. apple app store mockup

Reply
avatar
April 11, 2020 at 4:14 PM

I was suggested this website by my cousin. I’m not sure whether this post is written by him as no one else know such detailed about my trouble. You’re wonderful! Thanks! app store screenshots

Reply
avatar
April 14, 2020 at 3:39 PM

Follow this simple system on the off chance that you need to change over flip video on macintosh to iTunes, iDVD, from this drop-up show, you can discover a progression of other pragmatic alternatives to change over flip video to iDVD, Apple TV, PSP and so forth and most regular video organizations and normal sound configurations. FLV to MP4 video converter

Reply
avatar
April 17, 2020 at 11:23 AM

Hey! This is kind of off topic but I need some advice from an established blog. Is it difficult to set up your own blog? I’m not very techincal but I can figure things out pretty quick. I’m thinking about creating my own but I’m not sure where to start. Do you have any ideas or suggestions? Cheers imac template

Reply
avatar
May 11, 2020 at 1:03 AM

Wow, superb weblog structure! How long have you been blogging for? you make blogging glance easy. The total look of your web site is excellent, neatly as the content material! mobile app developers

Reply
avatar
May 13, 2020 at 8:09 PM

I feel like I’m often looking for interesting things to read about a variety of niches, but I manage to include your blog among my reads every day because you have compelling entries that I look forward to. Here’s hoping there’s a lot more amazing material coming! web design agency

Reply
avatar
May 20, 2020 at 4:37 PM

listed below are a couple of urls to internet websites we connect to for the fact we feel they really are really worth browsing[...]… ui/ux designer

Reply
avatar
Anonymous
June 24, 2020 at 2:56 AM

Can you please share how to append text in a existing pdf file

Reply
avatar
January 1, 2021 at 12:36 PM

Selenium can also be used as a web-scraping tool or to create a human-replica bot to automate social-media or even test PDF files! https://www.vanguardngr.com

Reply
avatar