Set Firefox Preference 1
2
3
FirefoxProfile profile = new FirefoxProfile ();
profile . setPreference ( "browser.helperApps.neverAsk.saveToDisk" , "application/zip" );
driver = new FirefoxDriver ( profile );
In case we download .csv file:
Set Firefox Preference fo CSV File 1
profile . setPreference ( "browser.helperApps.neverAsk.saveToDisk" , "text/csv" );
..or pdf file:
title: Set Firefox Preference for PDF File 1
profile . setPreference ( "browser.helperApps.neverAsk.saveToDisk" , "application/pdf" );
We can also apply settings for a list of all downloadable files:(application/... 부분은 엔터없이 "application/x-xpinstall;application/x-zip;application/x-zip-compressed;application/octet-stream;application/zip;application/pdf;application/msword;text/plain;application/octet"같이 붙여 쓸 것)
Set Preferences for All Types of Files 1
2
3
4
5
6
7
8
9
10
profile . SetPreference ( "browser.download.dir" , downloadDir );
profile . SetPreference ( "browser.download.folderList" , 2 );
profile . SetPreference ( "browser.helperApps.neverAsk.saveToDisk" ,
"application/x-xpinstall;
application/x-zip;
application/x-zip-compressed;
application/octet-stream;
application/zip;application/pdf;
application/msword;
text/plain;application/octet" );
The best place in code to apply setPreferences of Firefox is @BeforeClass:
Set Preferences for All Types of Files 1
2
3
4
5
6
7
8
9
10
11
12
13
@BeforeClass
public static void initializeClass () throws FileNotFoundException ,
IOException {
profile = new FirefoxProfile ();
profile . setPreference ( "browser.helperApps.neverAsk.saveToDisk" , "application/zip" );
driver = new FirefoxDriver ( profile );
properties = new PropertiesUtil ( PROPERTIES_FILE );
driver . get ( properties . getValue ( "URL" ));
driver . manage (). window (). maximize ();
screenshot = new ScreenshotUtil ( driver );
}