-1

I have a requirement to download a PDF file using Selenium Webdriver (#Java). Steps:

  1. Save Product
  2. Click on Print
  3. New window with url opens
  4. Save PDF.

Can anybody please help me in automating the above steps.

piet.t
  • 11,718
  • 21
  • 43
  • 52
MGUPTA
  • 5
  • 5
    What have you tried? Please read [ask]. – BadZen Apr 23 '19 at 05:34
  • please share some more information @MGUPTA what have you tried – akshay patil Apr 23 '19 at 05:43
  • Till now I have tried using the below code provide by Colin, also saw the code provided by others but my main issue is I have to automate the Print page. Clear steps are as follows.. 1. Navigate to Application 2. Add any item to your wishlist 3. Place order of the item. 4. Once order placed we will be having option to Print that order statement. 5. clicked on print 6. Now from Print page inspite og taking out the print I have to save the order in PDF(Save as PDF) under any directory. We are using Chrome to test the application not Mozilla. Hope now I am clear with the question – MGUPTA Apr 30 '19 at 11:28

1 Answers1

0

For downloads, I put the follwing code before instantiating the Chrome browser

HashMap<String, Object> chromePrefs = new HashMap<>();
        chromePrefs.put("profile.default_content_settings.popups", 0);
        chromePrefs.put("download.default_directory", "YouSaveDirectoryHere");

        ChromeOptions options = new ChromeOptions();
        options.setExperimentalOption("prefs", chromePrefs);

        DesiredCapabilities cap = DesiredCapabilities.chrome();
        cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        cap.setCapability(ChromeOptions.CAPABILITY, options);

        options.merge(cap);

This automatically downloads the file without a popup when clicking on the download button.

Hope it helps!

Calin Jula
  • 23
  • 1
  • 4