"ChromeOptions.AddUserProfilePreference"在Selenium C#中以错误的格式更新



我想更新Selenium C#中的Chrome配置文件首选项,通过添加以下行作为Chrome选项的一部分,使弹出窗口消失。

string url = "https://google.com";
string envName = "xyz.qa";
ChromeOptions.AddUserProfilePreference("protocol_handler.allowed_origin_protocol_pairs." + url + "." + envName, true);

然而,上面的行导致以错误的格式更新chrome配置文件首选项文件,即当遇到时。(点(在首选项名称中,它不会被抑制。

预期:"protocol_handler":{"allowed_origin_procol_pairs":{";https://google.com"{"xyz.qa":真}}}

实际:"protocol_handler":{"allowed_origin_procol_pairs":{";https://google"{"com":{"xyz";{"qa":真

第二种方法:

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

应为:";protocol_handler":{"allowed_origin_procol_pairs":{";https://google.com"{"xyz.qa":真}}}

实际:";protocol_handler":{"allowed_origin_procol_pairs":{";https://google.com"{"xyz.qa":[]}}}

一切看起来都很好,除了值true,它正在被[]取代。

我尝试了不同的方法来纠正格式,但没能纠正。请建议我如何以预期格式更新首选项文件。

最后,当url或应用程序名称包含时,能够找出如何更新ChromeProfile首选项。(点(。希望这能帮助人们通过代码处理Chrome安全弹出窗口。

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);

最新更新