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.