Print Style Sheet and Export a Webpage to PDF in Selenium WebDriver
Print style sheets format a web page for printing.
A repost of my daughter’s article with permission. I added a few notes. This is also included in my “How to in Selenium WebDriver” series.
Exporting a web page to PDF in automated tests as a test artifact can be useful for manual inspection later. For example, a suite of automated tests might generate multiple different customer invoices. After execution, manual testers can open and verify the printed invoices (PDF) look as expected.
Selenium v4 made exporting to PDF easy with driver.save_print_page
.
Sample page: login in WhenWise as the test business account and view an invoice. The page looks like this:
Below is the current PDF-printed version of a WhenWise invoice (admin view, strictly no need to be printer-friendly, I will make it so):