【问题标题】:ChromeDriver 2.29 Unable to set automatic downloads to Allow by defaultChromeDriver 2.29 无法将自动下载设置为默认允许
【发布时间】:2017-04-06 14:28:07
【问题描述】:

升级到 ChromeDriver 2.29 后,“自动下载 'localhost:9000”的默认值设置为“询问”。每当我的测试单击调用下载的链接时,就会打开“另存为”窗口对话框。以前它会静默下载到 Chrome 的默认下载文件夹。

如何在 chromedriver(不是 chrome)中将此设置的默认值更改为“允许”?

我尝试过使用 chrome.switches,但它们不起作用:

chrome.switches=--disable-extensions,--disable-infobars,--allow-insecure-localhost,--safebrowsing-disable-download-protection

Chrome 中的默认设置是所有网站的“允许”。 'http://localhost:9000' 也已添加到例外列表中。

【问题讨论】:

标签: google-chrome selenium selenium-chromedriver


【解决方案1】:

您可以使用功能设置默认下载位置。它会将文件下载到该文件夹​​,不会弹出任何窗口

试试下面的代码

DesiredCapabilities capabilities = new DesiredCapabilities();
String downloadPath = System.getProperty("user.dir")+ "\\Downloads";

HashMap<String, Object> chromePrefs = new HashMap<>();
chromePrefs.put("download.default_directory", downloadPath);
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("safebrowsing.enabled", "true");

ChromeOptions options = new ChromeOptions();

HashMap<String, Object> chromeOptionsMap = new HashMap<>();
options.setExperimentalOption("prefs", chromePrefs);
options.addArguments("--test-type");

capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY,chromeOptionsMap);
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

如果您遇到任何问题,请告诉我

【讨论】:

  • 我不想使用 DesiredCapabilities/Chrome 选项。而是将其用作 Chrome 开关或通过命令行参数。
  • 使用功能有什么区别
  • 测试自动化框架是使用自动处理 ChromeDriver 调用的 Serenity BDD 框架构建的。我们可以在属性文件中或通过命令行传递“chrome.switches”。因此,我要求一种不涉及使用 DesiredCapabilities 的方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-11-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多