How to handle file download popup using Selenium WebDriver?

前端 未结 3 2154
醉话见心
醉话见心 2020-12-01 22:52

I have written a code to download an excel file, it is working, but it stops as soon as the popup appears. Automatically it should download the file and store in specified l

3条回答
  •  抹茶落季
    2020-12-01 23:20

    Try to use this code:

    FirefoxProfile profile = new FirefoxProfile();
    WebDriver driver = new FirefoxDriver(profile); 
    
    profile.setPreference("browser.helperApps.neverAsk.saveToDisk" , "application/octet-stream;application/csv;text/csv;application/vnd.ms-excel;"); 
    profile.setPreference("browser.helperApps.alwaysAsk.force", false);
    profile.setPreference("browser.download.manager.showWhenStarting",false);
    profile.setPreference("browser.download.folderList", 2); 
    profile.setPreference("browser.download.dir","e:\\SampleExcel"); 
    

提交回复
热议问题