如何在C#Selenium Chrome驱动程序中认证(用户/密码)代理 [英] How to authenticate (user/password) proxy in c# selenium chrome driver

查看:257
本文介绍了如何在C#Selenium Chrome驱动程序中认证(用户/密码)代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTTP/HTTPS代理,需要使用用户名和密码进行身份验证.如何使用C#硒铬网络驱动程序来做到这一点?

I have a HTTP/HTTPS proxy which need to authenticate using username and password. How do I do that using C# selenium chrome webdriver?

string host = proxies[count].Split(':')[0];
int port = Convert.ToInt32(proxies[count].Split(':')[1]) + 1;

string prox = host + ":" + port.ToString();

OpenQA.Selenium.Proxy proxy = new OpenQA.Selenium.Proxy();
proxy.HttpProxy = prox;
proxy.SslProxy = prox;
options.Proxy = proxy;

options是我分配给驱动程序的ChromeOptions类.

options is the ChromeOptions class which I assign to the driver.

推荐答案

我发现的唯一成功方法是使用AutoIT( https://www.autoitscript.com/site/autoit ).

The only successful approach I have found is to use AutoIT ( https://www.autoitscript.com/site/autoit ).

我为所有主要的浏览器设置了我的代理身份验证设置,但是对于Chrome浏览器应该可以使用. 我是从记忆中在手机上写的.如果不起作用,请告诉我,我会纠正.

I have mine setup for proxy authentication for all of the major browsers, but this should work for Chrome. I wrote this on my phone from memory. If it doesn't work let me know and I'll correct.

WinWait("data:, - Google Chrome","","10")
If WinExists("data:, - Google Chrome","")Then
WinActivate("data:, - Google Chrome")
Send("USERNAMEGOESHERE"{TAB}")
Send("USERPASSWORDGOESHERE"{ENTER}")

使用AutoIT,将其创建为脚本,将其编译为exe,将其保存在某个位置,然后使用以下代码(Java代码)引用该文件:

Using AutoIT, create this as a script, compile it to exe, save it somewhere and reference the file with the following (Java code):

Runtime.getRuntime().exec("C:\\users\\USERID\\desktop\\FILENAME.exe");

我发现最好在调用触发代理身份验证的URL之前先调用代理脚本.

I find it best to call the proxy script a step BEFORE you call the URL that triggers the proxy auth.

这篇关于如何在C#Selenium Chrome驱动程序中认证(用户/密码)代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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