C#中硒的webdriver Firefox配置文件 - 使用代理与认证 [英] C# Selenium WebDriver FireFox Profile - using proxy with Authentication

查看:1040
本文介绍了C#中硒的webdriver Firefox配置文件 - 使用代理与认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您在下面的代码,如果你的代理服务器要求身份验证,然后Firefox会带来身份验证对话框,基本上你不能自动填充它设置代理服务器的参数。
所以是有无论如何设置的 USERNAME 密码

When you set proxy server parameter in the code below if your proxy server requires authentication then FireFox will bring Authentication dialog and basically you can't fill it in automatically. So is there is anyway to set USERNAME and PASSWORD ?

FirefoxProfile profile = new FirefoxProfile();
String PROXY = "192.168.1.100:8080";
OpenQA.Selenium.Proxy proxy = new OpenQA.Selenium.Proxy();
proxy.HttpProxy=PROXY;
proxy.FtpProxy=PROXY;
proxy.SslProxy=PROXY;
profile.SetProxyPreferences(proxy);
FirefoxDriver driver = new FirefoxDriver(profile);

如果您尝试代理字符串格式,以类似的东西的http://用户名:pass@192.168.1.1:8080
你得到错误字符串无效。所以我想有必须是实现这一目标的一种方式。

If you try to format proxy string to something like that http://username:pass@192.168.1.1:8080 You get error that string is invalid. So I wonder there is must be a way of achieving this.

任何帮助,将不胜感激。

Any help would be appreciated.

推荐答案

你可以做的是创建一个配置文件,并保存在它的认证数据。

What you can do is to create a profile and save the authentication data in it. If your profile is called "webdriver" you can select it from your code in the initialization:

ProfilesIni allProfiles = new ProfilesIni(); 
FirefoxProfile profile = allProfiles.getProfile("WebDriver"); 
profile.setPreferences("foo.bar",23);
WebDriver driver = new FirefoxDriver(profile);

这篇关于C#中硒的webdriver Firefox配置文件 - 使用代理与认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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