Java – download files using selenium
•
Java
I'm using selenium to test the system
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 can't find why the dialog box is still open Any ideas?
Thank you in advance
Solution
I got it!
When creating a driver, you must pass the Firefox configuration file as a parameter, 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 create drivers without parameters Now it's working
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
