如何在 Java 中找到 Chrome 下载路径 [英] How to find Chrome download path in Java
问题描述
我正在尝试使用 Chrome 浏览器使用 Webdriver 编写测试,我想下载一些文件,当我单击下载链接时,文件会自动下载到下载文件夹.我想知道是否有某种方法可以找出下载文件夹的当前路径(Win/Linux)Chrome 是否有一些配置文件保存它的设置?
I'm trying to write a test with Webdriver by using Chrome browser, I want to download some file, when I click download link, the file is being downloaded automatically to download folder. I was wondering if there is some way to find out what is the current path of the download folder (Win / Linux) Is there some configuration file where Chrome keep it settings ?
比
推荐答案
Google chrome 正在维护一个名为 Preferences 的自定义配置的配置文件,该文件采用 JSON 格式.所以你必须阅读这个文件.你将从这个文件中得到下载文件夹的当前路径.
Google chrome is maintaining one config file for such custom configuration Named as Preferences which is in JSON format.So you have to read this file.You will get the current path of download folder from this file.
"download": {
"default_directory": "CURRENT_PATH_OF_YOUR_DOWNLOAD_FOLDER",
"directory_upgrade": true,
"extensions_to_open": "",
"prompt_for_download": false
},
解析 JSON 文件 Java这将帮助您阅读该文件.
Parsing JSON File Java This will help you to read that file.
这个配置文件的位置在 Linux 中是
/USER_HOME_FOLDER/.config/chromium/Default/Preferences而在 Windows 中是
C:UsersUSER_ACCOUNTAppDataLocalGoogleChromeUser DataDefaultPreferences
Location of this configuration file
In Linux is
/USER_HOME_FOLDER/.config/chromium/Default/Preferences
and in Windows is
C:UsersUSER_ACCOUNTAppDataLocalGoogleChromeUser DataDefaultPreferences
这篇关于如何在 Java 中找到 Chrome 下载路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!