我尝试从firefox下载文件,但我不能处理保存对话框,即使我使用firefox配置文件如下。事实上,我想接受和取消对话框继续测试,但在我的情况下,它保存文件,但对话框仍然显示。
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);
}
谢谢,
您可以使用Robot类来处理弹出窗口的实时保存对话框打开文件对话框这个链接将帮助您进一步了解。机器人类的使用