I am using selenium for testing a system.
I have to download a text file. In order to download it directly I've created a Firefox profile which should avoid the Save / cancel dialog... butthe dialog is still coming.
My code is as follows:
FirefoxProfile fxProfile = new FirefoxProfile();
fxProfile.setPreference("browser.download.folderList",2);
fxProfile.setPreference("browser.download.manager.showWhenStarting",false);
fxProfile.setPreference("browser.download.dir","c:\\tmp");
fxProfile.setPreference("browser.helperApps.alwaysAsk.force", false);
fxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/plain");
driver.findElement(By.id("link-download")).click();
I cannot find why the dialog is still opened. Any idea?
Thanks in advance.
I got it.
The Firefox profile has to be passed as a parameter when creating the driver as follows:
FirefoxProfile fxProfile = new FirefoxProfile();
fxProfile.setPreference("browser.download.folderList", 2);
fxProfile.setPreference("browser.download.manager.showWhenStarting", false);
fxProfile.setPreference("browser.download.dir","c:\\tmp");
fxProfile.setPreference("browser.helperApps.alwaysAsk.force", false);
fxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream");
setDriver(TestBench.createDriver(new FirefoxDriver(fxProfile)));
I wass creating the driver without parameters. Now it is working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With