我正在尝试将 Selenium 与 Java 一起使用,并通过更新 chrome 版本 86 进行自动化,但它显示第三方 cookie 已禁用。我正在处理的网站需要 3rd 方 cookie。
我尝试使用以下代码启用 cookie:
ChromeOptions options = new ChromeOptions();
options.addArguments("incognito");
options.addArguments("start-maximized");
// options.addArguments("disable-infobars");
options.addArguments("ignore-certificate-errors");
options.addArguments("disable-popup-blocking");
options.addArguments("disable-extensions");
options.addArguments("disable-notifications");
options.addArguments("no-sandbox");
options.addArguments("allow-running-insecure-content");
options.setAcceptInsecureCerts(true);
options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
HashMap<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_settings.cookies", 0);
options.setExperimentalOption("prefs", prefs);
Boolean headless = Boolean.valueOf(ApplicationProperties.getInstance().getProperty("headless"));
if (Boolean.TRUE.equals(headless)) {
options.addArguments("headless");
options.addArguments("window-size=1600x1200");
}
options.setCapability(ChromeOptions.CAPABILITY, options);
options.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR,
UnexpectedAlertBehaviour.IGNORE);````
不启用 cookie。指导我怎么办?