小编Vis*_*tap的帖子

如何使用 webdriver 在 firefox 中处理下载 .xlsx 文件,其中窗口弹出窗口默认为“打开方式”单选按钮而不是“保存文件”

我有一个带有链接的 Web 应用程序。单击此链接时,它会打开弹出窗口,要求使用特定应用程序打开文件。

我编写了以下代码来创建 firefox 配置文件,它适用于其他文件扩展名,但不适用于 .xlsx 文件。

        profile.setEnableNativeEvents(true);

        profile.setPreference("browser.download.folderList", 2);
        profile.setPreference("browser.download.manager.showWhenStarting", false);
        profile.setPreference("browser.download.dir", System.getProperty("user.dir")+"\\src\\com\\Download");
        profile.setPreference("browser.download.downloadDir", System.getProperty("user.dir")+"\\src\\com\\Download");
        profile.setPreference("browser.download.defaultFolder", System.getProperty("user.dir")+"\\src\\com\\Download");
        profile.setPreference("browser.download.manager.closeWhenDone", true);
        profile.setPreference("pdfjs.disabled", true);
        profile.setPreference("browser.helperApps.alwaysAsk.force", false);
        profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/xls, application/zip,text/csv,application/msword,application/excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/pdf," +
                "application/vnd.ms-excel,application/msword,application/unknown,application/vnd.openxmlformats-officedocument.wordprocessingml.document");
Run Code Online (Sandbox Code Playgroud)

下面是我得到的弹出窗口:- 弹出窗口

  • 我认为,由于窗口弹出窗口未默认为“保存文件”单选按钮,因此 Firefox 配置文件不起作用。任何解决方案来处理这种情况?

java firefox popupwindow savefiledialog selenium-webdriver

2
推荐指数
1
解决办法
2403
查看次数