1

I wanted to update Chrome Profile preferences in Selenium C# to make a popup disappear by adding following line as part of Chrome Options.

string url = "https://google.com";
string envName = "xyz.qa";

ChromeOptions.AddUserProfilePreference("protocol_handler.allowed_origin_protocol_pairs." + url + "." + envName, true);

However the above line is resulting in updating chrome profile preference file in a wrong format i.e., when it encounters .(dot) in preference name it is not getting suppressed.

Expected: "protocol_handler":{"allowed_origin_protocol_pairs":{"https://google.com":{"xyz.qa":true}}}

Actual: "protocol_handler":{"allowed_origin_protocol_pairs":{"https://google" {"com":{"xyz" {"qa":true}}}}}

Second approach:

string jsonValue = "{ " + url + ":{ " + envName + ":true} }";
var obj = JObject.Parse(jsonValue);
ChromeOptions.AddUserProfilePreference("protocol_handler.allowed_origin_protocol_pairs", obj);

Expected: "protocol_handler":{"allowed_origin_protocol_pairs":{"https://google.com":{"xyz.qa":true}}}

Actual: "protocol_handler":{"allowed_origin_protocol_pairs":{"https://google.com" :{"xyz.qa":[] }}}

Everything looks good except the value true, it is getting replaced with [].

I tried different ways to correct the format but not able to get it corrected. Please suggest how do I update the preference file in expected format.

Subba Changa
  • 194
  • 2
  • 15

1 Answers1

3

Finally, able to figure out how to update the ChromeProfile preferences when the url or app name contains . (dot). Hope this helps someone to handle the Chrome Security popup through code.

var first = new Dictionary<string, object> { };
var second = new Dictionary<string, object> { };
options.prefs = new Dictionary<string, object> { };

first.Add("<<ApplicationName>>." + "<<Environment>>", false);
second.Add("<<ApplicationURL>>", first);
options.AddUserProfilePreference("protocol_handler.allowed_origin_protocol_pairs", second);
Subba Changa
  • 194
  • 2
  • 15