问题
I am unable to understand the meaning of following lines of code for setting up Chromeoptions in selenium code Can someone explain its meaning and als provide some external link for further learning -:
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);
prefs.put("profile.default_content_setting_values.notifications", 2);
options.setExperimentalOption("prefs", prefs);
Any help on this issue will be highly appreciated.
回答1:
Here is the complete details :
ChromeOptions options = new ChromeOptions();
Through this line you are creating an object by the name options of ChromeOptions Class.
Map<String, Object> prefs = new HashMap<String, Object>();
Here you have created a new Map object by the name prefs where the Key and Value fields accepts String and Object type of data and casted it to HashMap.
prefs.put("credentials_enable_service", false);
prefs.put("profile.password_manager_enabled", false);
prefs.put("profile.default_content_setting_values.notifications", 2);
In these three lines you have configured the pref-names within the prefs object.
options.setExperimentalOption("prefs", prefs);
Finally in this line you are using the setExperimentalOption method to set these experimental options (ChromeDriver options not yet exposed through the ChromeOptions API) within the options object.
Now you can use this options object of ChromeOptions Class to initialize the WebDriver and Web Client as follows :
WebDriver driver = new ChromeDriver(options);
回答2:
These are chrome browser preferences. You can set using options. You can find full list here in source code of chromium
https://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/pref_names.cc?view=markup
来源:https://stackoverflow.com/questions/49465124/chromeoptions-and-setexperimentaloption-code