1

Using ChromeDriver version 80.0.3987.106 and the Chrome Capabilities Below. I want to download a PDF to my local default Downloads location so that the test code can read it for assertions. However, the file is opening in a new Tab in the browser.

public DesiredCapabilities getDesiredCapabilities(Proxy proxySettings) {
    TestContext.get().setBrowser("Chrome", "latest");
    ChromeOptions options = new ChromeOptions();
    HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
    chromePrefs.put("profile.default_content_settings.popups", 0);
    chromePrefs.put("safebrowsing.enabled", "true");
    chromePrefs.put("download.default_directory","C:\\Users\\varghesevineeth\\Desktop\\Vineeth" );
    chromePrefs.put("profile.default_content_setting_values.notifications", 2);
    chromePrefs.put("plugins.plugins_disabled", new String[] { "Adobe Flash Player", "Chrome PDF Viewer" });
    chromePrefs.put("plugins.always_open_pdf_externally", true);
    chromePrefs.put("pdfjs.disabled", true);
    chromePrefs.put("profile.default_content_setting_values.automatic_downloads", 1);
    options.setExperimentalOption("prefs", chromePrefs);
    options.addArguments("test-type");
    options.addArguments("--ignore-certifcate-errors");
    options.addArguments("--disable-extensions");
    options.addArguments("start-maximized", "disable-popup-blocking");
    options.addArguments("disable-infobars");
    options.addArguments("--disable-application-cache");

    DesiredCapabilities chromeCapabilities = DesiredCapabilities.chrome();
    chromeCapabilities.setCapability("name", MDC.get("testname"));
    chromeCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    chromeCapabilities.setCapability(ChromeOptions.CAPABILITY, options);
    chromeCapabilities.setCapability("download.prompt_for_download", false);
    return addProxySettings(chromeCapabilities, proxySettings);
}
Brydenr
  • 798
  • 1
  • 19
  • 30
vini007
  • 595
  • 1
  • 6
  • 13
  • I am using ChromeDriver 80.0.3987.106 – vini007 Mar 04 '20 at 16:17
  • 1
    Put that info into the question. Have you tried switching to the other tab ? Selenium allows you to switch between tabs and windows. – MasterJoe Mar 04 '20 at 16:20
  • Why do i need to switch? I just need to download the PDF to the Browser Default Downloads Folder on clicking the link – vini007 Mar 04 '20 at 16:23
  • "so that the test code can read it for assertions." what does this mean ? what are you testing ? – MasterJoe Mar 04 '20 at 16:25
  • I need to download a PDF file on clicking a link in the application rather than opening it in a new Tab – vini007 Mar 04 '20 at 16:27
  • Take a look at https://stackoverflow.com/questions/46937319/how-to-use-chrome-webdriver-in-selenium-to-download-files-in-python – DMart Mar 04 '20 at 19:52

0 Answers0