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

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

C#中的源代码请。

谢谢

您不必将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); 

感谢您的帮助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实例打开。

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

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