gpt4 book ai didi

java - 如何在 chromedriver 中禁用 "This type of file can harm your computer. Do you want to keep file.xml anyway?"?

转载 作者:太空宇宙 更新时间:2023-11-04 11:12:41 24 4
gpt4 key购买 nike

我正在使用 Selenide 框架和 Java 来编写一些自动化测试。我的测试之一是文件下载。单击下载按钮后,Chrome 会显示消息“这种类型的文件可能会损害您的计算机。您是否仍要保留 file.xml?”。是否可以禁用此功能?我尝试了下面的代码,但它对我不起作用。

System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("safebrowsing.enabled", "true");
options.setExperimentalOption("prefs", prefs);
ChromeDriver chromeDriver = new ChromeDriver(options);
Configuration.browser = "chrome";

最佳答案

我找到了解决方案。我只是创建实现 WebDriverProvider 的类

public class CustomWebDriverProviderChrome implements WebDriverProvider {
public WebDriver createDriver(DesiredCapabilities capabilities) {

HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.prompt_for_download", "true");
chromePrefs.put("safebrowsing.enabled", "true");
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);

return new ChromeDriver(cap);
}
}

关于java - 如何在 chromedriver 中禁用 "This type of file can harm your computer. Do you want to keep file.xml anyway?"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45817998/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com