When the browser starts, the proxy settings are successfully installed.
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);
But I need to be able to change them during execution, without restarting the browser. Internet search has not brought anything. Interested in any ways to solve the problem, not only by means of Selenium
I already wrote a function that allows you to change non-boolean Preferences. Here it is
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();
}
I can also change boolean preferences, but i can't read value what already written. I can only change value on the opposite. How i can read preference value? To know whether to change it or not.
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();");
}