【发布时间】:2020-07-20 01:12:31
【问题描述】:
我想更新 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 配置文件首选项文件,即,当它在首选项名称中遇到 .(dot) 时,它不会被抑制。
预期: "protocol_handler":{"allowed_origin_protocol_pairs":{"https://google.com":{"xyz.qa":true}}}
实际: "protocol_handler":{"allowed_origin_protocol_pairs":{"https://google" {"com":{"xyz" {"qa":true}}}}}
第二种方法:
string jsonValue = "{ " + url + ":{ " + envName + ":true} }";
var obj = JObject.Parse(jsonValue);
ChromeOptions.AddUserProfilePreference("protocol_handler.allowed_origin_protocol_pairs", obj);
预期:"protocol_handler":{"allowed_origin_protocol_pairs":{"https://google.com":{"xyz.qa":true}}}
实际:"protocol_handler":{"allowed_origin_protocol_pairs":{"https://google.com" :{"xyz.qa":[] }}}
一切看起来都不错,除了值 true,它被替换为 []。
我尝试了不同的方法来更正格式,但无法更正。请建议我如何以预期格式更新首选项文件。
【问题讨论】:
-
这方面有什么帮助吗?
-
对此有何建议?
标签: c# selenium google-chrome chrome-options