Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a proxy for Chrome Driver in Selenium

I am using Selenium Webdriver using C# for Automation in Chrome browser. I need to check if my webpage is bloced in Some regions(some ip ranges). So I have to set a proxy in my Chrome browser . I tried the below code. The proxy is being set but I get an error. Could some one help me.

        ChromeOptions options = new ChromeOptions();

        options.AddArguments("--proxy-server=XXX.XXX.XXX.XXX");

        IWebDriver Driver = new ChromeDriver(options);

        Driver.Navigate().GoToUrl("myUrlGoesHere");

When I run this code, I get the following message in my Chrome browser: I tried to enable the Proxy option, but the ' Change proxy settings' option is disabled.

*Unable to connect to the proxy server

A proxy server is a server that acts as an intermediary between your computer and other servers. Right now, your system is configured to use a proxy, but Google Chrome can't connect to it. If you use a proxy server... Check your proxy settings or contact your network administrator to make sure the proxy server is working. If you don't believe you should be using a proxy server: Go to the Chrome menu > Settings > Show advanced settings... > Change proxy settings... > LAN Settings and deselect "Use a proxy server for your LAN". Error code: ERR_PROXY_CONNECTION_FAILED*

like image 997
Ajay S Avatar asked Jan 01 '15 11:01

Ajay S


People also ask

Can you use proxies with Selenium?

We can run a proxy with Selenium webdriver in Python. A proxy is an essential component to do localization testing. We can take an e-commerce application and check if the language and currency visible is as per the user location. Import webdriver from Selenium package.


Video Answer


2 Answers

I'm using the nuget packages for Selenium 2.50.1 with this:

ChromeOptions options = new ChromeOptions();
proxy = new Proxy();
proxy.Kind = ProxyKind.Manual;
proxy.IsAutoDetect = false;
proxy.HttpProxy =
proxy.SslProxy = "127.0.0.1:3330";
options.Proxy = proxy;
options.AddArgument("ignore-certificate-errors");
var chromedriver = new ChromeDriver(options);
like image 142
Bron Davies Avatar answered Sep 28 '22 15:09

Bron Davies


If your proxy requires user log in, you can set the proxy with login user/password details as below:

options.AddArguments("--proxy-server=http://user:[email protected]:8080");
like image 34
Surya Avatar answered Sep 28 '22 15:09

Surya