ChromeOptions AddUserProfilePreference

2020-07-29 02:29发布

问题:

I am using Webdriver 3.3.1 with Java. I am trying to disable the pop-up asking to save passwords. Based on search results I need to use ChromOptions.AddUserProfilePreference("","") However, there is no AddUserProfilePreference the only add method is addArguments.

I am using Eclipse Neon.2 and Java 1.8

回答1:

With ChromeDriver 2.28 & Selenium 3.3.1, the following works:

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


回答2:

Add the below chrome options:

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