I have a scenario to test where I download a PDF file from UI and compare the content of PDF with an image. This image is just a small portion of the PDF.

I am downloading the PDF using Selenium and taking the screenshot of an element and saving it as image. Is there a possible way to verify whether that image is present in PDF.

1 Answer 1


Selenium can only driver the browser. So after you have downloaded a file you need some other way to check its content.

The technique is called template matching, finding an image within another image.

I think you can use ImageMagick to convert the PDF to a image and then check the image contains another image.

Probably you have to make sure the image you are comparing have the same resolution...

So yes it is possible, but it won't be straightforward and easy to implement, better to ask some developers to help you. Also question yourself what are you testing? Testing with image comparing is prone to a lot of maintenance, can you trust the PDF library todo its work? Unit-test the generations behavior and just check the file is generated in the end-to-end test?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.