C# Selenium如何在此过程中更改浏览器设置

C# Selenium如何在此过程中更改浏览器设置,c#,selenium,C#,Selenium,浏览器启动时,代理设置将成功安装 FirefoxOptions options = new FirefoxOptions(); options.SetPreference("network.proxy.http", proxy); options.SetPreference("network.proxy.http_port", port); options.SetPreference("network.proxy.ftp", proxy); options.SetPreference("ne

浏览器启动时,代理设置将成功安装

FirefoxOptions options = new FirefoxOptions();

options.SetPreference("network.proxy.http", proxy);
options.SetPreference("network.proxy.http_port", port);

options.SetPreference("network.proxy.ftp", proxy);
options.SetPreference("network.proxy.ftp_port", port);

options.SetPreference("network.proxy.ssl", proxy);
options.SetPreference("network.proxy.ssl_port", port);

options.SetPreference("network.proxy.socks", proxy);
options.SetPreference("network.proxy.socks_port", port);

options.SetPreference("network.proxy.type", 1);
IWebDriver driver = new OpenQA.Selenium.Firefox.FirefoxDriver(options);
但我需要能够在执行期间更改它们,而无需重新启动浏览器。互联网搜索并没有带来任何东西。对任何解决问题的方法感兴趣,而不仅仅是通过硒

我已经编写了一个函数,允许您更改非布尔首选项。给你

void SetPreference(string preferenceName, string value, IWebDriver driver)
        {
            IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
            js.ExecuteScript($"document.getElementById(\"textbox\").value = '{preferenceName}'");
            js.ExecuteScript("FilterPrefs()");
            js.ExecuteScript("view.selection.currentIndex = 0");
            js.ExecuteScript("ModifySelected();");

            IAlert alert = driver.SwitchTo().Alert();
            alert.SendKeys(value);
            alert.Accept();
        }
我还可以更改布尔首选项,但我无法读取已经写入的值。我只能改变相反方向的值。如何读取首选项值?知道是否要改变它

void ChangeBoolValue(string preferenceName, IWebDriver driver)
        {
            IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
            js.ExecuteScript($"document.getElementById(\"textbox\").value = '{preferenceName}'");
            js.ExecuteScript("FilterPrefs()");
            js.ExecuteScript("view.selection.currentIndex = 0");
            js.ExecuteScript("ModifySelected();");
        }

希望这有帮助:是的,它帮助了我,我已经编写了一个函数,允许您更改非布尔首选项。我也可以更改布尔首选项,但我无法确定是真还是假。如何读取首选项值?