I am testing a page I am building and I was hoping to find out if it is possible to accept the download prompt using selenium? I am using the Firefox Webdriver.
Asked
Active
Viewed 5,743 times
1
-
1Selenium is not able to accept OS level dialogs, it was not built for that - the answer below *should* work. – Arran Jun 19 '13 at 14:07
-
Related: https://stackoverflow.com/questions/13839544/using-selenium-webdrivers-method-browser-helperapps-neverask-savetodisk-how-ca – Gabriel Devillers Jan 05 '19 at 15:09
4 Answers
5
You can try using the following code, for downloading a zip file:
FirefoxProfile profile = new FirefoxProfile();
//MIME type for zip file "application/zip"
profile.setPreference("browser,helperapps.neverAsk.SaveToDisk", "application/zip");
// 0 = desktop, 1 = default download folder , 2 = user defined location.
profile.setPreference("browser.download.folderList",0);
driver = new FirefoxDriver(profile);
baseUrl = " http://www.yourwebsite.com ";
driver.get(baseUrl);
driver.findElement(By.id("downloadFile")).click;

Chris Kinniburgh
- 391
- 3
- 17

Shammi
- 203
- 2
- 4
- 8
2
The easiest way to do this is to set have your test use a firefox profile that is setup to automatically accept the download prompt. See here for help creating a new profile. To use this profile in your test see the top answer to the question here. However I also recommend reading this, which will explain why you don't actually need to download the files to test that your download functionality is working.

Community
- 1
- 1

confusified
- 2,320
- 7
- 22
- 29
-
The link to explain why you don't need to download files is dead. It's now located here: http://ardesco.lazerycode.com/testing/webdriver/2012/07/25/how-to-download-files-with-selenium-and-why-you-shouldnt.html – Scone Jan 11 '18 at 05:02
0
Why don't you choose Sikuli, it is too simple.
Add sikuli-java.jar file in build path, install Picpick soft, save images of save file, ok button using Picpick.
Type the following commands
new Screen().click(new Pattern("E:\\simage\\save.png")); //here e:\\..is image file path
new Screen().click(new Pattern("E:\\simage\\ok.png"));
It's over.

pinckerman
- 4,115
- 6
- 33
- 42