简体   繁体   中英

How can i handle download firefox dialogbox (accept download and cancel it ) + selenium java

I try to download files from firefox but i can't handle save dialogbox even i used firefox profile as below. in fact, i want to accept and cancel dialogbox to continue the test but in my case it save the file but the dialogBox still displayed.

 else if(browserName.equals("FF")) {
      
     System.setProperty("webdriver.gecko.driver", 
             prop.getProperty("FirefoxDriver_win64"));
   
   FirefoxOptions FfOptions = new FirefoxOptions();       
   FfOptions.setCapability("marionette", true);  
     
    FirefoxProfile profile = new FirefoxProfile();
    
    profile.setPreference("browser.download.panel.shown", false);
    profile.setPreference("browser.helperApps.neverAsksaveToDisk", "application/x-msexcel,text/html,application/xop+xml,application/vnd.ms-excel.sheet.binary.macroenabled.12,application/vnd.wap.wbxml,application/octet-stream,application/x-authorware-bin,application/x-bcpio,text/plain,application/x-msdownload,application/excel,application/x-excel,application/excel,application/x-excel,application/excel,application/vnd.ms-excel,application/x-excel,application/x-msexcel");       profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv,application/vnd.ms-excel");
    profile.setPreference("browser.download.folderList", 2);
    profile.setPreference("browser.download.dir","C:\\Users\\PC\\git\\downloadFile");

     FfOptions.setProfile(profile);
     driver = new FirefoxDriver(FfOptions);
 }

Thanks,

You can use Robot class to deal with popups live save dialogue open file dialogue this link will help you to understand further. Usage of Robot Class

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