Answer the question
In order to leave comments, you need to log in
How to setup proxy in selenium??
How to set up proxy in selenium. I found an example that does not work for me here it is:
public void proxy(int port, String ip, String userName, String password) throws Exception {//
String host = ip+":"+port;
proxy = new Proxy();
proxy
.setHttpProxy(host)
.setFtpProxy(host)
.setSslProxy(host)
.setSocksProxy(host)
.setProxyType(Proxy.ProxyType.MANUAL)
.setSocksUsername(userName)
.setSocksPassword(password);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver2 = new ChromeDriver(capabilities);
driver2.get("https://2ip.ru/");//Этот только чтобы проверить чтобы прокси работало
}
Answer the question
In order to leave comments, you need to log in
Worked with sel+phanjs.
In Phantom js proxy are registered when creating a driver in the constructor
caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
Config.dir + "//browser//phantomjs");
String user = Config.PROXY_CREDENTIALS.get("user");
String password = Config.PROXY_CREDENTIALS.get("password");
// create screen
caps.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
// use proxy
proxy = Config.getProxy();
caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] { "--load-images=false",
"--proxy=" + proxy, String.format("--proxy-auth=%s:%s", user, password) });
// use user agent
caps.setCapability("phantomjs.page.settings.userAgent", Config.getUserAgent());
try {
// create phantomjs
driver = new PhantomJSDriver(caps);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question