简体   繁体   中英

How to save a downloaded file into a particular folder in Java selenium?

I am able to download a zip file from my app, using robot class, but how can I save that zip into a specific folder?

Please help me on this.

The simplest answer for me to give would be to use java to copy the download to somewhere else using Java. (If you don't know how to do that, there are plenty of explanations here on SO).

However, I don't know what your robot class is doing, nor what browser you have. If you are using the robot class to press OK, you can probably also use it to type in the path.

However, if you are using FirefoxDriver, my favorite way is to enable automatic downloading. When you create your instance of FirefoxDriver, create a FirefoxProfile to pass in with the following settings:

FirefoxProfile profile = new FirefoxProfile();

            //Enable automatic downloading
            profile.setPreference("browser.download.folderList",2);
            profile.setPreference("browser.download.manager.showWhenStarting",false);;
            profile.setPreference("browser.download.dir","SOMEFOLDERGOESHERE");
            profile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/octet-stream");
FirefoxDriver driver = new FirefoxDriver(profile);

You will need to replace application/octet-stream with the MIME type of download you are trying to download.

This will allow you to automatically download a file to a specific folder.

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