Learning Chrome options

The WebDriver APIs provide techniques to pass capabilities to ChromeDriver. The ChromeOptions class is one such technique that is supported by Java.

Let's look at an example of the Save password dialog that shows up when you log in to an application on Google Chrome, as shown in the following screenshot:

We need to prevent this dialog from appearing, so we need to use ChromeOptions. We create an object of ChromeOptions, which is then passed to the ChromeDriver constructor. This object contains convenient methods for setting ChromeDriver- specific capabilities.

The following code disables the Save password popup for Chrome:

 ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("credentials_enable_service", false);
prefs.put("profile.password_manager_enabled", false);
options.addArguments("disable-extensions");
options.addArguments("--start-maximized");
options.setExperimentalOption("prefs", prefs);
System.out.println("Before logging");
logMessage(log, "Opening Browser");
System.out.println("After logging");
driver = new ChromeDriver(options);

Here, the log is the Logger object (Log4J). setExperimentalOption sets an experimental option. It is used for setting new ChromeDriver options that are not yet exposed through the ChromeOptions API. The preceding code starts a Chrome browser session in which notifications are suppressed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.200.143