Doc*_*Who 5 java pdf firefox automation selenium-webdriver
我正在尝试使用带有Java的Selenium Web驱动程序下载pdf文件.我上次约两周前运行它时效果很好,但现在每次点击pdf链接时都会打开pdf阅读器.
我在测试中创建的我的firefox配置文件没有被更改,它设置了一个下载位置并设置文件,如果它们是pdf或csv则自动下载.csv文件仍然可以正常工作并下载到正确的文件夹.
在我的代码中,我将pdfjs.disabled设置为true,如果我在webdriver firefox实例中打开about:config,我可以看到这是正确设置的.
如果我在另一个firefox实例中将pdfjs.disabled设置为true并手动单击链接,则它可以正常工作.
自从我上次运行测试以来我不确定firefox是否已更新,但我还在我的计算机上安装了adobe reader.
请有人能告诉我它可能会突然停止工作吗?
这是我创建的配置文件以及我调用webdriver的方式.我使用的是最新版本的Firefox 21.0.
FirefoxProfile firefoxProfile = new FirefoxProfile();
// Set profile to accept untrusted certificates
firefoxProfile.setAcceptUntrustedCertificates(true);
//Set profile to not assumet certificate issuer is untrusted
firefoxProfile.setAssumeUntrustedCertificateIssuer(false);
//Set download location and file types
firefoxProfile.setPreference("browser.download.folderList",2);
firefoxProfile.setPreference("browser.download.manager.showWhenStarting",false);
firefoxProfile.setPreference("browser.download.dir",reportFolder);
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv,application/pdf,application/csv,application/vnd.ms-excel");
// Set to false so popup not displayed when download finished.
firefoxProfile.setPreference("browser.download.manager.showAlertOnComplete",false);
firefoxProfile.setPreference("browser.download.manager.showAlertOnComplete",false);
firefoxProfile.setPreference("browser.download.manager.showWhenStartinge",false);
firefoxProfile.setPreference("browser.download.panel.shown",false);
firefoxProfile.setPreference("browser.download.useToolkitUI",true);
// Set this to true to disable the pdf opening
firefoxProfile.setPreference("pdfjs.disabled", true);
driver = new FirefoxDriver(firefoxProfile);
Run Code Online (Sandbox Code Playgroud)
更新:我删除了adobe reader,这又开始了.读者必须在配置文件中设置我需要禁用的内容才能使其与读者一起工作.有人有什么想法吗?
尝试
firefoxProfile.setPreference("plugin.disable_full_page_plugin_for_types", "application/pdf,application/vnd.adobe.xfdf,application/vnd.fdf,application/vnd.adobe.xdp+xml");
Run Code Online (Sandbox Code Playgroud)
诀窍是将 PDF MIME 添加到plugin.disable_full_page_plugin_for_types首选项中。
这适用于 Firefox 26。
| 归档时间: |
|
| 查看次数: |
4679 次 |
| 最近记录: |