Selenium Webdriver - 如何为Firefox设置代理以“自动检测”

时间:2012-03-31 01:27:13

标签: c# selenium selenium-webdriver webdriver

我的脚本在chrome和IE上正常运行,但由于firefox为其代理设置设置了“manual”,因此无法在firefox上启动。如何将其设置为“自动检测”?

C#中的源代码。

由于

3 个答案:

答案 0 :(得分:4)

您不必将firefox设置为自动检测。转到http://wpad/wpad.dat,它将返回设置代理的javascript文件。你可以在里面找到代理地址。 然后使用以下代码来实现技巧

FirefoxProfile profile = new FirefoxProfile();
            String PROXY = "xx.xx.xx.xx: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);

答案 1 :(得分:1)

感谢您的帮助AJ。

我使用以下代码来解决我的问题:

FirefoxBinary binary = new FirefoxBinary("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
FirefoxProfile profile = new FirefoxProfile("C:\\test profile\\");          driver = new FirefoxDriver(binary, profile);

我只是将我的Mozilla个人资料的内容复制到"c:\test profile\"。这允许我通过Selenium运行测试,但也保持其他firefox实例打开。

答案 2 :(得分:0)

您只需将此来源添加到您的程序中:

FirefoxProfile profile = new FirefoxProfile();
String PROXY = "your URL WEB proxy:YourPort";
OpenQA.Selenium.Proxy proxy = new OpenQA.Selenium.Proxy();
proxy.HttpProxy = PROXY;
proxy.FtpProxy = PROXY;
proxy.SslProxy = PROXY;
profile.SetProxyPreferences(proxy);
相关问题