-1

I'm trying to download a file from a website that has to be saved in a specific folder. Website http://bookboon.com/en/basics-of-accounting-information-processing-ebook When I click on download it saves the file in the download section, I also tried to change the download directory in chrome settings, it doesn't work. I am trying automation (selenium, java). Is there any way?

public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", "C:\\Users\\User_2\\Downloads\\chromedriver_win32\\chromedriver.exe");
        d = new ChromeDriver();
        d.get("http://bookboon.com/en/basics-of-accounting-information-processing-ebook");

            d.findElement(By.id("email")).sendKeys("asd@ymail.com");
            WebElement One=d.findElement(By.xpath("html/body/div[1]/div/article/div/section[1]/form/div[2]/div[2]/div[1]/input"));
            One.sendKeys("Studying");
            One.sendKeys(Keys.TAB);

            WebElement Two=d.findElement(By.xpath("html/body/div[1]/div/article/div/section[1]/form/div[2]/div[2]/div[2]/input"));
            Two.sendKeys("Engineer/Science MSc");
            Two.sendKeys(Keys.TAB);

            WebElement Three=d.findElement(By.xpath("html/body/div[1]/div/article/div/section[1]/form/div[2]/div[2]/div[3]/input"));
            Three.sendKeys("All India Institute of Medical Sciences (AIIMS), Delhi");
            Three.sendKeys(Keys.TAB); 





            d.navigate().back();
            downlinks = d.findElements(By.className("pdf"));

    }
}
zappee
  • 20,148
  • 14
  • 73
  • 129
  • You can set Chrome download folder as explained in [this answer](https://stackoverflow.com/a/19024814/753136). – tiktak Oct 10 '17 at 05:41

1 Answers1

0

For Chromedriver It will work

String downloadFilepath = "/path/to/download";
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", downloadFilepath);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(cap);

For Firefox: You need to setPreference

    profile.setPreference("browser.download.dir", "Filepath");

Hope this helps. :)

Zakaria Shahed
  • 2,589
  • 6
  • 23
  • 52