0

我试图设置所有可能的首选项,以避免打开并保存文件对话框,同时使用硒下载文件。首选项设置为避免在Firefox下载对话框不工作PDF

它正在为文本文件,但不适用于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硒版本

请帮助我使它适用于PDF,Excel和Word文件

谢谢!

+0

PDF文件正在发生什么? –

+0

打开或保存文件对话框正在显示PDF,Excel和工作文件 –

+0

您可以缩小您的问题到PDF,Excel和Word中的任何一种文件类型吗? – DebanjanB

回答

0

我发现的一个解决方案是使用ProfileIni类。它允许你加载一个预制的firefox配置文件。您可以使用如下图所示

private ProfilesIni init = new ProfilesIni(); 
private FirefoxProfile profile = init.getProfile("QA"); 
private WebDriver driver = new WebDriver(profile); 

然后,您可以将所有这些偏好的直上的个人资料,并设置设置跳过下载对话框,并自动保存到你想要的目标文件夹,并保持对每一个设置测试用例,你需要下载东西