在Selenium中设置Chrome驱动程序代理 [英] Setting a proxy for Chrome Driver in Selenium

查看:412
本文介绍了在Selenium中设置Chrome驱动程序代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Chrome浏览器中使用使用C#for Automation的Selenium Webdriver。
我需要检查我的网页是否存在于某些区域(某些IP范围)。所以我必须在我的Chrome浏览器中设置代理。我尝试了下面的代码。代理正在设置,但我得到一个错误。有人可以帮助我。

  ChromeOptions options = new ChromeOptions(); 

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

IWebDriver Driver =新的ChromeDriver(选项);

Driver.Navigate()。GoToUrl(myUrlGoesHere);

运行此代码时,我的Chrome浏览器中收到以下消息:我试图启用代理选项,但'更改代理设置'选项被禁用。



*无法连接到代理服务器



<代理服务器是充当您的计算机与其他服务器之间的中介的服务器。目前,您的系统已配置为使用代理,但Google Chrome无法连接到该代理。
如果您使用代理服务器...
请检查您的代理设置,或联系您的网络管理员以确保代理服务器正常工作。如果您不相信您应该使用代理服务器:请转到Chrome菜单>设置>显示高级设置...>更改代理设置...>局域网设置,然后取消选择为您的局域网使用代理服务器。
错误代码:ERR_PROXY_CONNECTION_FAILED *

解决方案

我使用Selenium 2.50.1的nuget包:

  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 =新的ChromeDriver(选项);


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*

解决方案

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);

这篇关于在Selenium中设置Chrome驱动程序代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆