简体   繁体   中英

How do I accept the download prompt on the firefox webdriver using selenium in JAVA?

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.

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; 

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.

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.

是的,sikuli是一个简单的解决方案,您可以使用它

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM