1

Question - After Setting Firefox profile, Firefox keeps asking download location when downloading CSV file. Please help.

System.setProperty("webdriver.gecko.driver", "..\\C_Automation\\Files\\geckodriver64_15.0.exe");
        FirefoxProfile Profile = new FirefoxProfile();
        Profile.setPreference("browser.download.dir",downloadFilepath);
        Profile.setPreference("browser.download.folderList",2);
        Profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv");
        Profile.setPreference("browser.download.manager.showWhenStarting",false);
        Profile.setPreference("browser.helperApps.neverAsk.openFile","text/csv");
        Profile.setPreference("browser.helperApps.alwaysAsk.force", false);
        driver = new FirefoxDriver(Profile);
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
user7615535
  • 31
  • 2
  • 10
  • Which version of Mozilla Firefox are you using? Can you confirm once the attribute is `helperApps.neverAsk.saveToDisk` ? Can you help me with a snapshot please? – undetected Selenium May 19 '17 at 16:50
  • Firefox version is 52.0.2(64-bit). Dont know how to upload snapshot. – user7615535 May 19 '17 at 21:46
  • I have an Answer for your Question. But I need to test my Solution before I handover to you. So can I have the URL of the Website from where you are trying to download csv file? Thanks – undetected Selenium May 20 '17 at 09:58

1 Answers1

1

I don't see any major issue in your code. But while you setPreference for the FirefoxProfile Class do remember to add all the relevant Multipurpose Internet Mail Extensions of CSV type files referred in this site.

Here is your own code block with some simple tweaks added to it:

String downloadFilepath = "C:\\Utility\\OP_Resources\\MozillaFirefoxDownload";
System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
FirefoxProfile Profile = new FirefoxProfile();
Profile.setPreference("browser.download.dir",downloadFilepath);
Profile.setPreference("browser.download.folderList",2);
//neverAsk - saveToDisk - CSV        
Profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/csv,application/excel,application/vnd.ms-excel,application/vnd.msexcel,text/anytext,text/comma-separated-values,text/csv,text/plain,text/x-csv,application/x-csv,text/x-comma-separated-values,text/tab-separated-values");
//neverAsk - saveToDisk - ANY       
Profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/xml,text/plain,text/xml,image/jpeg,application/octet-stream");
Profile.setPreference("browser.download.manager.showWhenStarting",false);
//neverAsk - openFile - CSV
Profile.setPreference("browser.helperApps.neverAsk.openFile","application/csv,application/excel,application/vnd.ms-excel,application/vnd.msexcel,text/anytext,text/comma-separated-values,text/csv,text/plain,text/x-csv,application/x-csv,text/x-comma-separated-values,text/tab-separated-values");
//neverAsk - openFile - ANY
Profile.setPreference("browser.helperApps.neverAsk.openFile","application/xml,text/plain,text/xml,image/jpeg,application/octet-stream");
Profile.setPreference("browser.helperApps.alwaysAsk.force", false);

I have verified my code on this site and Microsoft site as well and seems to me works fine.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks for your try but after adding everything what you suggested, firefox still opening open/save file window. – user7615535 May 21 '17 at 17:49
  • @TJ1985 Refer to my previous comment under your question `I have an Answer for your Question. But I need to test my Solution before I handover to you. So can I have the URL of the Website from where you are trying to download csv file?` Thanks – undetected Selenium May 21 '17 at 18:30
  • I wish i could give you but my client website is domain based so it wouldn't work in outsider laptop. If you r okay, i can work with you on decided time to share my screen and show you what i am getting. Please let me know your available time. – user7615535 May 22 '17 at 15:10
  • Can you quickly install Team Viewer v12 on your machine so we can work in tandem? – undetected Selenium May 22 '17 at 15:12
  • I know there is a issue while downloading from Microsoft sites, how about setting `browser.helperApps.neverAsk.saveToDisk` & `browser.helperApps.neverAsk.openFile` to each & ever type of file? Thanks – undetected Selenium May 22 '17 at 15:14
  • @TJ1985 Check my updated Answer, works for ANY site & ANY type of file. Thanks – undetected Selenium May 22 '17 at 16:06
  • I just added below code as you recommended but still no luck Profile.setPreference("browser.helperApps.neverAsk.saveToDisk", CSV); Profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "ANY"); Profile.setPreference("browser.helperApps.neverAsk.openFile","CSV"); Profile.setPreference("browser.helperApps.neverAsk.openFile","ANY"); – user7615535 May 23 '17 at 02:32
  • THANK YOU VERY VERY MUCH. FINALLY YOUR CODE WORKED. APPRECIATED YOUR TIME & EFFORT TO HELP ME. Since i am new to Stackoverflow, not sure how to recommend you. I will try to give points/recommendations for any users. – user7615535 May 23 '17 at 02:44
  • Is it possible to save default download location for IE11 browser so after clicking on download link, it doesn't ask any save file question ? – user7615535 May 23 '17 at 03:13