How to save as PDF on Chrome using Selenium

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?


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.

1
Answers

Replies

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


DesiredCapabilities cap = DesiredCapabilities.chrome();


cap.setCapability("download.default_directory","C:");


cap.setCapability("download.prompt_for_download","false");


cap.setCapability("directory_upgrade","true");


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.

 
 

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.
To Top