How to download CSV file through Firefox Profile in Java(如何在 Java 中通过 Firefox Profile 下载 CSV 文件)
问题描述
问题 - 设置 Firefox 配置文件后,Firefox 在下载 CSV 文件时不断询问下载位置.请帮忙.
Question - After Setting Firefox profile, Firefox keeps asking download location when downloading CSV file. Please help.
System.setProperty("webdriver.gecko.driver", "..\C_Automation\Files\geckodriver64_15.0.exe");
FirefoxProfile Profile = new FirefoxProfile();
Profile.setPreference("browser.download.dir",downloadFilepath);
Profile.setPreference("browser.download.folderList",2);
Profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv");
Profile.setPreference("browser.download.manager.showWhenStarting",false);
Profile.setPreference("browser.helperApps.neverAsk.openFile","text/csv");
Profile.setPreference("browser.helperApps.alwaysAsk.force", false);
driver = new FirefoxDriver(Profile);
推荐答案
我在您的代码中没有发现任何重大问题.但是,当您为 FirefoxProfile
类 setPreference
时,请记住添加此 Multipurpose Internet Mail Extensions="http://mimeapplication.net/" rel="nofollow noreferrer">网站.
I don't see any major issue in your code. But while you setPreference
for the FirefoxProfile
Class do remember to add all the relevant Multipurpose Internet Mail Extensions
of CSV type files referred in this site.
这是您自己的代码块,其中添加了一些简单的调整:
Here is your own code block with some simple tweaks added to it:
String downloadFilepath = "C:\Utility\OP_Resources\MozillaFirefoxDownload";
System.setProperty("webdriver.gecko.driver", "C:\Utility\BrowserDrivers\geckodriver.exe");
FirefoxProfile Profile = new FirefoxProfile();
Profile.setPreference("browser.download.dir",downloadFilepath);
Profile.setPreference("browser.download.folderList",2);
//neverAsk - saveToDisk - CSV
Profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/csv,application/excel,application/vnd.ms-excel,application/vnd.msexcel,text/anytext,text/comma-separated-values,text/csv,text/plain,text/x-csv,application/x-csv,text/x-comma-separated-values,text/tab-separated-values");
//neverAsk - saveToDisk - ANY
Profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/xml,text/plain,text/xml,image/jpeg,application/octet-stream");
Profile.setPreference("browser.download.manager.showWhenStarting",false);
//neverAsk - openFile - CSV
Profile.setPreference("browser.helperApps.neverAsk.openFile","application/csv,application/excel,application/vnd.ms-excel,application/vnd.msexcel,text/anytext,text/comma-separated-values,text/csv,text/plain,text/x-csv,application/x-csv,text/x-comma-separated-values,text/tab-separated-values");
//neverAsk - openFile - ANY
Profile.setPreference("browser.helperApps.neverAsk.openFile","application/xml,text/plain,text/xml,image/jpeg,application/octet-stream");
Profile.setPreference("browser.helperApps.alwaysAsk.force", false);
我已在此 网站 和 Microsoft 验证了我的代码site 在我看来工作正常.
I have verified my code on this site and Microsoft site as well and seems to me works fine.
这篇关于如何在 Java 中通过 Firefox Profile 下载 CSV 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Java 中通过 Firefox Profile 下载 CSV 文件


- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01