我试图设置所有可能的首选项以避免在使用 selenium 下载文件时打开和保存文件对话框。
它适用于文本文件,但不适用于 PDF 文件
以下是首选项集:
String downloadPath = <some random path>;
String mimetypes = "application/vnd.pdf,application/vnd.adobe.xfdf,text/csv,application/x-msexcel,application/excel,application/pdf,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml";
String url = "http://only-testing-blog.blogspot.in/2014/05/login.html";
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.panel.shown", false);
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.download.dir", downloadPath);
profile.setPreference("browser.helperApps.neverAsk.openFile", mimetypes);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", mimetypes);
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
profile.setPreference("browser.download.manager.focusWhenStarting", false);
profile.setPreference("browser.download.manager.useWindow", false);
profile.setPreference("browser.download.manager.showAlertOnComplete", false);
profile.setPreference("browser.download.manager.closeWhenDone", false);
FirefoxDriver driver = new FirefoxDriver(profile);
driver.get(url);
driver.findElement(By.xpath("//a[contains(.,'Download PDF File')]")).click();
我正在使用带有2.53.0 selenium 版本的Firefox 46
请帮助我使它也适用于 PDF、Excel 和 Word 文件
谢谢!