Это код, который я написал:
public static void main(String args[]){
FirefoxProfile ffProfile = new FirefoxProfile();
FirefoxBinary ffBinary = new FirefoxBinary();
ffBinary.setTimeout(TimeUnit.SECONDS.toMillis(60));
ffProfile.setPreference("browser.download.dir","C:\\ComonFiles");
ffProfile.setPreference("browser.download.folderList", 2);
ffProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;"
+ "application/pdf;"
+ "application/xml;"
+ "text/xml;"
+ "application/zip;"
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document;" + "text/plain;"
+ "text/csv");
System.setProperty("webdriver.gecko.driver","D:\\geckodriver.exe");
WebDriver driver = new FirefoxDriver(ffBinary, ffProfile);
//Some other operations
downloadFile1();
downloadFile2();
}
public static void downloadFile1()
{
//Click on download button
}
public static void downloadFile2()
{
ffProfile.setPreference("browser.download.dir","C:\\WorkingFiles");
//Click on download button
}
Я хочу загрузить File2 в какую-то отдельную папку с именем C:\\WorkingFiles
, но она не отменяет настройки загрузки, даже если я снова вызываю set preference в downloadFile2()
. Он всегда загружает все файлы в C:\\ComonFiles
. Это все еще использует предпочтение основной функции для загрузки.