ChromeOptions AddUserProfilePreference

时间:2017-03-28 18:58:03

标签: java selenium webdriver

我正在使用带有Java的Webdriver 3.3.1。我试图禁用弹出窗口要求保存密码。根据我需要使用的搜索结果 ChromOptions.AddUserProfilePreference( “”, “”) 但是,没有AddUserProfilePreference 唯一的添加方法是addArguments。

我正在使用Eclipse Neon.2和Java 1.8

2 个答案:

答案 0 :(得分:6)

使用ChromeDriver 2.28& Selenium 3.3.1,以下作品:

final DesiredCapabilities capabilities = DesiredCapabilities.chrome();
final ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--start-maximized");
Map<String, Object> prefs = new LinkedHashMap<>();
prefs.put("credentials_enable_service", Boolean.valueOf(false));
prefs.put("profile.password_manager_enabled", Boolean.valueOf(false));
chromeOptions.setExperimentalOption("prefs", prefs);
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
WebDriver driver = new ChromeDriver(capabilities);

答案 1 :(得分:4)

添加以下Chrome选项:

Map<String, Object> prefs =new HashMap<String, Object>();
ChromeOptions options = new ChromeOptions();
options.addArguments("disable-extensions");
prefs .put("credentials_enable_service", false);
prefs .put("profile.password_manager_enabled", false);
options.setExperimentalOption("prefs", prefs);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);