Monday, 7 April 2014

Handle Download popup using Firefox Browser Profile


Note|  Text in Blue [#PYTHON] and Orange [#JAVA] can be edited or mentioned important for the entire blog. All the posts are practically done by me.


Firefox Browser Profile [Download Files]

This is the continuation of my previous topics, #link1 and #link2.  The simplest way to ignore Browser pop-up and save files is to make use of Browser profiles;  There are couple of ways to do this [can be done either manually or using scripts]

Advantages of using Browser Profile
    1| Skip download pop-up and save the files on specific folder
    2| No need of 3rd party tools like AutoIT or Java Robot



#Method1

Before you start working with pop-ups on Browser profiles, make sure that the Download options are set default to Save File.

(Open Firefox) Tools > Options > Applications





#Method2


Make use of the below snippet and do edits whenever necessary.


FirefoxProfile profile = new FirefoxProfile();

String path = "C:\\Test\\";
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.dir", path);
profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/msword, application/csv, application/ris, text/csv, image/png, application/pdf, text/html, text/plain, application/zip, application/x-zip, application/x-zip-compressed, application/download, application/octet-stream");
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.download.manager.focusWhenStarting", false);  
profile.setPreference("browser.download.useDownloadDir", true);
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
profile.setPreference("browser.download.manager.closeWhenDone", true);
profile.setPreference("browser.download.manager.showAlertOnComplete", false);
profile.setPreference("browser.download.manager.useWindow", false);
profile.setPreference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", false);
profile.setPreference("pdfjs.disabled", true);
       
driver = new FirefoxDriver(profile);

14 comments:

  1. It was very nice article and it is very useful to Selenium learners.We also provide Cub training software online training.

    ReplyDelete
  2. My download pop up displays radio buttons open File and save File need to select save File and press enter. Please help me understand how to handle this.

    ReplyDelete
    Replies
    1. You can use the tab like, robot.keyPress(keyEvent.vk_TAB). First we need to check the pop-up manually using tab press or enter etc. so that we will come to know about its behavior. Then try to use the above piece of code. It will work. But you need to check how many time you need to tabs and where to hit the enter.

      Delete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Thanks for the great information in your blog Selenium Training in Chennai

    ReplyDelete
  5. In my download popup there is no option for Tab on 'Save' link to download the file. Please Suggest how I can Proceed further.

    ReplyDelete
  6. Well explained. Got to learn new things from your Blog on Appium.
    Appium training in chennai

    ReplyDelete
  7. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium.selenium training in chennai

    ReplyDelete

  8. Thanks for posting this useful content, Good to know about new things here, Let me share this, . VMWare training in pune

    ReplyDelete
  9. Advanced Selenium Framework Training in Chennai by Vishwa

    Hi, Reach Mr.Vishwa for Best Selenium and Coded UI Training in Chennai with real time project assistance. This people will teach everything from the basics up to advanced level scenarios from frameworks.

    I learned from Mr.Vishwa and Raj they are very good automation people for Selenium Frameworks. After joined with them I learned many things and now I am writing automation scripts in own project. Vishwa 9003085882
    selenium training in chennai

    ReplyDelete
  10. It was very nice blog to learn about Selenium.Thanks for sharing new things.selenium training in chennai

    ReplyDelete