How to save as PDF on Chrome using Selenium


I am trying to automate "Save as PDF" of Chrome using selenium. As far as I know, It is not supported by Selenium. Therefore, I am trying to write my own piece of code. I am currently having an issue, that is, by clicking on the Print button on my webpage, it opens a new window with a printable area. I am trying to switch to this window using SwitchTo command. But it times out every time. How do I solve this?



You will need to disable the Chrome PDF plugin and download the print window with desired compatibilities.

DesiredCapabilities cap =;




cap.setCapability("plugins.plugins_disabled","Chrome PDF Viewer");

WebDriver driver = new ChromeDriver(cap);

You can also add the options.AddArgument(“---printing”); to automatically click the print option.


If you want to unleash your potential in this competitive field, please visit the selenium course page for more information, where you can find the selenium tutorials and selenium frequently asked interview questions and answers as well.


This topic has been locked/unapproved. No replies allowed

Login to participate in this discussion.

Leave a reply

Before proceeding, please check your email for a verification link. If you did not receive the email, click here to request another.