ChromeDriver 2.29默认情况下无法将自动下载设置为“允许”

时间:2017-04-06 14:28:07

标签: google-chrome selenium selenium-chromedriver

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

如何将此设置的默认值更改为'允许'在chromedriver(不是铬)?

我尝试过使用chrome.switches但是他们没有工作:

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

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

enter image description here

1 个答案:

答案 0 :(得分:0)

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

试试以下代码行

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);

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