如何在Java中找到Chrome下载路径 [英] How to find Chrome download path in Java

查看:701
本文介绍了如何在Java中找到Chrome下载路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用Web浏览器用Webdriver写一个测试,我想下载一些文件,当我点击下载链接,该文件被自动下载到下载文件夹。
我想知道有没有办法找出下载文件夹(Win / Linux)的当前路径是什么
Chrome有哪些配置文件保存设置?



Thans

解决方案

Google Chrome维护一个这样的自定义配置的配置文件命名为首选项,其格式为 JSON 格式,因此您必须阅读此文件。您将从此文件获取当前下载文件夹的路径。

 下载:{
default_directory:CURRENT_PATH_OF_YOUR_DOWNLOAD_FOLDER,
directory_upgrade:true,
extensions_to_open ,
prompt_for_download:false
},

解析JSON文件Java
这将帮助您阅读该文件。



此配置文件的位置
在林ux是

/USER_HOME_FOLDER/.config/chromium/Default/Preferences
和Windows中是

C:\Users \USER_ACCOUNT\AppData\Local\Google\Chrome\User Data\Default\Preferences


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 ?

Thans

解决方案

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
 },

Parsing JSON File Java This will help you to read that file.

Location of this configuration file In Linux is
/USER_HOME_FOLDER/.config/chromium/Default/Preferences and in Windows is
C:\Users\USER_ACCOUNT\AppData\Local\Google\Chrome\User Data\Default\Preferences

这篇关于如何在Java中找到Chrome下载路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆