Chromeoptions and setExperimentalOption code

余生长醉 提交于 2020-06-01 00:59:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!