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/");//Этот только чтобы проверить чтобы прокси работало
}
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);