Save as PDF chrome using selenium

I'm looking to automate "Save as PDF" in Chrome using selenium. AFAIK not supported by selenium out of the box. So I am trying to write my own. I have a problem. In fact, clicking on the "Print" button on my web page opens a new window with the option to print. I am trying to switch to this window using SwitchTo. But this time is always.

+3


source to share


2 answers


You can add options .AddArgument ("- kiosk-print"); so that it automatically presses the print button. In the meantime, there is no need to know about it. ”



This works for me, but I have a problem setting up the printer to save as PDF. Instead, it prints to a printer.

+2


source


You can try to disable the Chrome pdf plugin and load the promt window with the required capabilities. Something like that:



    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);

      

+1


source







All Articles