i'm making proxy checker in selenium, there way can make go onto next proxy if takes more 15 seconds load?
so, if tries frist proxy, takes 15 or more seconds load, move onto next proxy
package a; import org.openqa.selenium.by; import org.openqa.selenium.webdriver; import org.openqa.selenium.webelement; import org.openqa.selenium.chrome.chromedriver; import org.openqa.selenium.remote.capabilitytype; import org.openqa.selenium.remote.desiredcapabilities; import java.io.*; public class main { public static void main(string[] args) throws ioexception, interruptedexception { bufferedreader br = new bufferedreader(new filereader("proxy.txt")); string line; bufferedwriter file = null; file = new bufferedwriter(new filewriter("proxy_out.txt")); while ((line = br.readline()) != null) { //splitting string str; str = line; string[] splited = line.split(":"); //system.out.println(arrays.tostring(splited)); string ip = splited[0]; string port = splited[1]; system.out.println(ip + ":" + port); string proxy = ip + ":" + port; org.openqa.selenium.proxy proxy = new org.openqa.selenium.proxy(); proxy.sethttpproxy(proxy) .setftpproxy(proxy) .setsslproxy(proxy); desiredcapabilities cap = new desiredcapabilities(); cap.setcapability(capabilitytype.proxy, proxy); webdriver driver = new chromedriver(cap); driver.get("google.com"); try { webelement check = driver.findelement(by.id("input_captcha")); if (check.isdisplayed()) { system.out.println(proxy + " good"); file.write(ip+":"+port); } } catch (exception e) { system.out.println("bad"); } driver.close(); } file.close(); } }
you may try using webdriverwait class below.
webdriverwait wait = new webdriverwait(driver, 15); //timeout 15 seconds webelement element = wait.until(expectedconditions.elementtobeselected(by.id("input_captcha")));
this code continually try find input_captcha element, until either element found or timeout reached
Comments
Post a Comment