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

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

问题描述

我在 Chrome 浏览器中使用 Selenium Webdriver 使用 C# 进行自动化.我需要检查我的网页是否在某些地区(某些 ip 范围)被阻塞.所以我必须在我的 Chrome 浏览器中设置一个代理.我试过下面的代码.正在设置代理,但出现错误.有人可以帮我吗.

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

运行此代码时,我在 Chrome 浏览器中收到以下消息:我尝试启用代理选项,但禁用了更改代理设置"选项.

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

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

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*

推荐答案

我正在使用 Selenium 2.50.1 的 nuget 包:

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天全站免登陆