How can i set proxy using selenium webdriver with browser HtmlunitDriver for Java? -


my name leo , java bot developer, using selenium webdriver , browser htmlunitdriver headless, question title says: know how set proxy using firefoxdriver don't wanna use ui browser because it's slow execute, so, searching in google , page don't found similar, if know how open url proxy using htmlunitdriver, please answer useful me, thanks.

i using firefoxdriver, wanna same htmlunitdriver.

org.openqa.selenium.proxy proxy = new org.openqa.selenium.proxy();     proxy.sethttpproxy("198.2.202.49:80")          .setftpproxy("198.2.202.49:80")          .setsslproxy("198.2.202.49:80");     desiredcapabilities cap = new desiredcapabilities();     cap.setcapability(capabilitytype.proxy, proxy);     webdriver driver = new firefoxdriver(cap); 

this answer own question, method "@raghav n" told me, lot! :d (y)

i , work perfectly, , can tested because open www.find-ip.net , scrapped proxy active, , same put.

here code working, if wanna test it, copy , paste in proyect. note: class proxy need "import org.openqa.selenium.proxy;"

htmlunitdriver driver = new htmlunitdriver();  proxy proxy = new proxy(); proxy.sethttpproxy("42.117.1.78:3128");  driver.setproxysettings(proxy); driver.manage().timeouts().implicitlywait(30,timeunit.seconds); driver.get("http://www.find-ip.net"); string ip = driver.findelement(by.xpath("//*[@id='ipbox']/div[1]/div[2]")).gettext(); // copia el texto del actual ip string pais = driver.findelement(by.xpath("//*[@id='ipbox']/div[2]/div[2]")).gettext(); //copia el texto del actual pais del proxy system.out.println("» ip ficticio: " + ip +" - country: " + pais); 

output:

ip: 42.117.1.78       -        country: viet nam 

if page dont load maybe proxy down try another.

i hope you, bye! :)


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -