Automated Testing PDF Download in Selenium WebDriver

How to test downloading PDFs in Selenium WebDriver

Zhimin Zhan
5 min readMay 3, 2022

--

A repost of my daughter’s article with permission and slight modification. I added it here for the convenience of my blog subscribers. You can find more Selenium examples like this one in my eBook: Selenium WebDriver Recipes in Ruby.

This is also included in my “How to in Selenium WebDriver” series.

Many websites feature links that download a PDF document. These PDF files might be static (e.g. a restaurant menu) or dynamically generated (e.g. a receipt).

This tutorial will show you how to download a PDF document and verify its contents in a Selenium WebDriver automated test script.

Table of Contents:
· Test Design
Saving the download file to a specific location
PDF verification library
· Open browser with specified download folder
· Download and Verify the downloaded file
· Verify the PDF
Verify PDF page count
Verify PDF contents
· Completed Test Script

Test Design

  1. Navigate to a web page and download the PDF
    For my example, I’m downloading a book sample PDF (static) at http://zhimin.com/books/pwta.
  2. Verify the downloaded PDF exists
    Once the file is downloaded from the…

--

--

Zhimin Zhan

Test automation & CT coach, author, speaker and award-winning software developer. Help teams succeed with Agile/DevOps by implementing real Continuous Testing.