在下面的问题中遇到问题,如何设置代理设置?
//sample code to add new proxy settings
firefoxProfile.SetPreference(“network.proxy.http_port”, 8080);
答案 0 :(得分:1)
检查this answer中共享的代码。
//Code copied from the above link
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);
将PROXY
设置为您的代理服务器地址。
对于Java用户
String PROXY = "proxyserver:9999";
org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setHttpProxy(PROXY);
proxy.setFtpProxy(PROXY);
proxy.setSslProxy(PROXY);
org.openqa.selenium.remote.DesiredCapabilities cap = org.openqa.selenium.remote.DesiredCapabilities.firefox();
cap.setCapability(org.openqa.selenium.remote.CapabilityType.PROXY, proxy);
org.openqa.selenium.WebDriver driver = new org.openqa.selenium.firefox.FirefoxDriver(cap);