简体   繁体   English

Selenium下载路径动态变化

[英]Dynamic change of Selenium download path

I've an instance of Selenium webdriver with a defined default download path (the prompt is disabled because I've to download a lot of files).我有一个 Selenium webdriver 的实例,它具有定义的默认下载路径(提示被禁用,因为我必须下载很多文件)。

I would like to let the user choose its own download path with a dialog box before starting to download but AFTER having created the Selenium instance.我想让用户在开始下载之前使用对话框选择自己的下载路径,但在创建 Selenium 实例之后。

Is is possible to change this path once the object has been created?创建 object 后是否可以更改此路径?

For this to work, you need to use the absolute path.为此,您需要使用绝对路径。 Here-这里-

Assuming 'filename' as variable.假设“文件名”为变量。

download_folder = r'C:\\Temp\\'+filename;

options.add_argument('--ignore-certificate-errors')
options.add_experimental_option("prefs", {
  "download.default_directory": os.path.abspath(download_folder),
  "download.prompt_for_download": False,
  "download.directory_upgrade": True,
  "safebrowsing.enabled": True
})

Mind the indentations:)注意缩进:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM