Is it possible to set a proxy programatically in webdriver for IE?
For Chrome, I do something like this:
ChromeOptions options = new ChromeOptions();
Proxy proxy = new Proxy();
proxy.HttpProxy = "http://proxy.com:8080";
proxy.SslProxy = "http://proxy.com:8080";
options.AddAdditionalCapability("proxy", proxy);
but this doesn't work for IE. I've also tried: options.AddAdditionalCapability(CapabilityType.Proxy, proxy); which doesn't work. Is there a comparable capability for IE?
Have you tried the latest IEDriverServer (version 2.34.0.0)? This is feature is very new to the IEDriverServer. The .NET bindings now expose the Proxy via the InternetExplorerOptions class.
This is the change log: https://code.google.com/p/selenium/source/detail?r=084758c6b515a2699b82c6bf5871e29b552cbc8f
You should be able to do the exact same thing now after updating the IEDriverServer and .NEt bindings:
InternetExplorerOptions options = new InternetExplorerOptions();
Proxy proxy = new Proxy();
proxy.HttpProxy = "http://proxy.com:8080";
proxy.SslProxy = "http://proxy.com:8080";
options.Proxy = proxy;
String PROXY = url://login:pass#proxy:port";
ChromeOptions options = new ChromeOptions();
options.AddArguments("user-data-dir=path/in/your/system");
Proxy proxy = new Proxy();
proxy.HttpProxy = PROXY;
proxy.SslProxy = PROXY;
proxy.FtpProxy = PROXY;
options.Proxy = proxy;
// Initialize the Chrome Driver
using (var driver = new ChromeDriver(options))
Related
Heading
Hi everyone!
I have been struggling with figuring out how to "allow all remote connections" with a proxy in ChromeDriver in C#.
======== START =============
ChromeDriverService service = ChromeDriverService.CreateDefaultService();
service.WhitelistedIPAddresses = ""; // NOTE: The idea is to allow all remote
connections. How to allow all IPs?
service.Port = 9515;
ChromeOptions options = new ChromeOptions();
var proxy = new Proxy();
proxy.Kind = ProxyKind.Manual;
proxy.IsAutoDetect = false;
proxy.HttpProxy = proxyUrl;
proxy.SslProxy = proxyUrl;
options.Proxy = proxy;
options.AddArgument("ignore-certificate-errors");
IWebDriver driver = new ChromeDriver(service, options);
int waitTime = GetRandomWait2to5.getRandom2to5();
driver.Url = "https://whatismyipaddress.com/"; //TEST
============ END =========================
See attached screenshot with "local connections allowed".
Passing "chrodriver --whitelisted-ips=''" in CMD works and says "all remote connections allowed".
Thanks for the input. (edited)
When you instantiate ChromeDriver a Chrome driver executable is launched, you need to pass --whitelisted-ips='' using options.AddArgument("--whitelisted-ips=''")
In your case:
ChromeDriverService service = ChromeDriverService.CreateDefaultService();
service.WhitelistedIPAddresses = ""; // NOTE: The idea is to allow all remote
connections. How to allow all IPs?
service.Port = 9515;
ChromeOptions options = new ChromeOptions();
var proxy = new Proxy();
proxy.Kind = ProxyKind.Manual;
proxy.IsAutoDetect = false;
proxy.HttpProxy = proxyUrl;
proxy.SslProxy = proxyUrl;
options.Proxy = proxy;
options.AddArgument("ignore-certificate-errors");
options.AddArgument("--whitelisted-ips=''"); // NEW LINE ADDED
IWebDriver driver = new ChromeDriver(service, options);
int waitTime = GetRandomWait2to5.getRandom2to5();
driver.Url = "https://whatismyipaddress.com/"; //TEST
Ok, that was way simpler than i thought: Replace service.WhitelistedIPAddresses = "" with service.WhitelistedIPAddresses = " ". This finally shows "All remote connections are allowed".
I try to use proxy with Authentication, but i have problems.
I try to use this code:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("ignore-certificate-errors");
chromeOptions.AddArgument("--ignore-ssl-errors");
chromeOptions.AddArgument("--proxy-server=http://" + "login:pass#IP:Port");
var driver = new ChromeDriver(chromeOptions);
driver.Navigate().GoToUrl("https://2ip.ru/");
But browser say me: "ERR_NO_SUPPORTED_PROXIES".
Proxy is ok. How can i solve this problem?
P.s. Also I try use this code:
ChromeOptions options = new ChromeOptions();
proxy = new Proxy();
proxy.Kind = ProxyKind.Manual;
proxy.IsAutoDetect = false;
proxy.HttpProxy =
proxy.SslProxy = "IP:Port";
proxy.SocksPassword = "pass";
proxy.SocksUserName = "login";
options.Proxy = proxy;
options.AddArgument("ignore-certificate-errors");
var chromedriver = new ChromeDriver(options);
I'm going to sent SOAP-request to the host via proxy. I use two variants: manual proxy settings and system proxy settings. There is my code:
if (UseProxy.Equals("manual"))
{
WebProxy p = new WebProxy(pServer, true)
{
Credentials = new NetworkCredential(ProxyUser, ProxyPass)
};
WebRequest.DefaultWebProxy = p;
Request.Proxy = p;
Request.Timeout = 10000;
}
else if(UseProxy.Equals("system"))
{
IWebProxy proxy = WebRequest.GetSystemWebProxy();
proxy.Credentials = CredentialCache.DefaultCredentials;
Request.Proxy = proxy;
Request.Timeout = 10000;
}
Manual settings are working well, but system proxy settings don't work at all. I can not send anything and program hangs out on request regardless of the timeout parameter.
Also I tried the following:
WebProxy proxy = new WebProxy(ProxyHost, 8080);
proxy.UseDefaultCredentials = true;
Request.UseDefaultCredentials = true;
WebRequest.DefaultWebProxy = proxy;
Request.Proxy = proxy;
Request.Timeout = 10000;
It didn't work too. Please explain me where is my error? Class with SOAP-requests was generated authomatically using wsdl-file.
I've got a windows service, that hosts WCF service inside.
Below is definition of how endpoint is initialized:
WebHttpBinding binding = new WebHttpBinding(WebHttpSecurityMode.TransportCredentialOnly);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
string url = ConfigurationManager.AppSettings["serviceUrl"];
Uri baseAddress = new Uri(url);
Uri metadataAddress = new Uri(url + "Description");
CallService service = new CallService(controller);
ServiceHost host = new WebServiceHost(service);
host.AddServiceEndpoint(typeof (ICallService), binding, baseAddress);
host.Authorization.PrincipalPermissionMode = PrincipalPermissionMode.UseWindowsGroups;
ServiceDebugBehavior stp = host.Description.Behaviors.Find<ServiceDebugBehavior>();
stp.HttpHelpPageEnabled = true;
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
smb.HttpGetUrl = metadataAddress;
host.Description.Behaviors.Add(smb);
host.Open();
The problem is that when accesing this WCF service using computer name (e.g http://mycomputer.mydomain.int:4544/Somthing) first I receive an authentication window, and after it HTTP:400.
Everything works fine if accessing service using http://localhost:4544/Something, or if switch off Windows Authentication.
What is wrong with it?
I know that this error is very common, but I tried to apply the solutions to this problem and could not solve it.
Thats my code:
var endpoint = new EndpointAddress(new Uri("http://www3prz.bancobonsucesso.com.br/Servicos/app.svc"), EndpointIdentity.CreateDnsIdentity("bancobonsucesso.com.br"));
var binding = new WSHttpBinding();
binding.UseDefaultWebProxy = true;
binding.Security.Mode = SecurityMode.Message;
binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
binding.Security.Message.EstablishSecurityContext = true;
binding.Security.Message.NegotiateServiceCredential = true;
var customBinding = new CustomBinding(binding);
SymmetricSecurityBindingElement security = customBinding.Elements.Find<SymmetricSecurityBindingElement>();
security.LocalClientSettings.MaxClockSkew = TimeSpan.MaxValue;
security.LocalClientSettings.DetectReplays = false;
SecureConversationSecurityTokenParameters secureTokenParams = (SecureConversationSecurityTokenParameters)security.ProtectionTokenParameters;
SecurityBindingElement bootstrap = secureTokenParams.BootstrapSecurityBindingElement;
bootstrap.LocalClientSettings.MaxClockSkew = TimeSpan.MaxValue;
bootstrap.LocalClientSettings.DetectReplays = false;
ws = new ServicoClient(customBinding, endpoint);
ws.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
ws.ClientCredentials.UserName.UserName = "test";
ws.ClientCredentials.UserName.Password = "test";
var return = ws.EmitirBoleto("test");
IN the WCF Binding use useDefaultWebProxy:
<bindings>
<basicHttpBinding>
<binding name="bindingName" useDefaultWebProxy="true">
WebProxy wproxy = new WebProxy("new proxy",true);
wproxy.Credentials = new NetworkCredential("user", "pass");
WebRequest.DefaultWebProxy = wproxy;
This error may arise problem with proxy settings.
Please check Proxy setting with your web browser. Just changed connection settings Option -> settings -> connection settings to Auto detect proxy settings
Good luck ...