List of usage examples for org.openqa.selenium WebDriver getCurrentUrl
String getCurrentUrl();
From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.login.LoginHandler32.java
License:Apache License
public void processDriver(WebDriver driver) { String OriginalURL = driver.getCurrentUrl(); driver.get(OriginalURL);// ww w. j a v a 2s . c om //Find the login button and click on it WebElement LoginButton = driver.findElement(By.linkText("Login")); LoginButton.click(); //Find the username textbox using the name of the textbox - which is typically "Username" WebElement useremail = driver.findElement(By.linkText("Username")); //if username is not found try finding an element with "email" if (null == useremail) { useremail = driver.findElement(By.linkText("email")); } useremail.clear(); useremail.sendKeys("cs572team32@gmail.com"); WebElement password = driver.findElement(By.linkText("Password")); password.clear(); password.sendKeys("ViewSonic"); WebElement submitButton = driver.findElement(By.linkText("submit")); submitButton.click(); }
From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.login.LoginHandler35.java
License:Apache License
public void processDriver(WebDriver driver) { String cur = driver.getCurrentUrl(); if (cur.contains("/members/") || cur.contains("slickguns.com/alerts/")) { Configuration conf = NutchConfiguration.create(); new WebDriverWait(driver, conf.getLong("libselenium.page.load.delay", 3)); // Wait for the page to load try {/*ww w .j av a 2 s . c o m*/ WebElement uname = driver.findElement(By.cssSelector("input[type=\"text\"]")); // handling multiple text boxes not needed for these pages WebElement remember = driver.findElement(By.cssSelector("input[type=\"checkbox\"]")); WebElement pwd = driver.findElement(By.cssSelector("input[type=\"password\"]")); uname.sendKeys("team35csci572@outlook.com"); // login info for all 403s pwd.sendKeys("qwer1234"); remember.click(); // Check Remember Me option :) pwd.submit(); } catch (Exception e) { } driver.navigate().refresh(); // new WebDriverWait(driver, 5)) // wait for click and any ending client process to compete execution (we are being generous here) } driver.close(); }
From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.login.LoginHandler36.java
License:Apache License
/** * Invokes a registered domain handler for handling the web page * @param driver selenium web driver instance *//*from w w w .jav a2 s . c om*/ @Override public void processDriver(WebDriver driver) { String domainName = getDomainName(driver.getCurrentUrl()); if (domainHandlers.containsKey(domainName)) { domainHandlers.get(domainName).handle(driver); } else if (jsRequiredDomains.contains(domainName)) { // this url needs javascript to be executed. // Selenium does it by itself, so nothing more to be done here! } }
From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.login.LoginHandler6.java
License:Apache License
public void processDriver(WebDriver driver) { //Handler for Login System.out.println(driver.getCurrentUrl()); System.out.println("handler called team 6"); if (driver.getCurrentUrl().equals("http://www.academy.com/")) { System.out.println("team 6- http://www.academy.com"); driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS); driver.findElement(By.id("level-six")).click(); WebElement emailButton = driver.findElement(By.id("WC_AccountDisplay_FormInput_logonId_In_Logon_1")); emailButton.clear();/* ww w.j a v a 2 s.c o m*/ emailButton.sendKeys("shrutimundra.20@gmail.com"); WebElement passButton = driver .findElement(By.id("WC_AccountDisplay_FormInput_logonPassword_In_Logon_1")); passButton.clear(); passButton.sendKeys("sgpsteam6\n"); } else if (driver.getCurrentUrl().equals("http://www.arguntrader.com/")) { WebElement emailButton = driver.findElement(By.id("username")); emailButton.clear(); emailButton.sendKeys("team6ir4"); WebElement passButton = driver.findElement(By.id("password")); passButton.clear(); passButton.sendKeys("sgpsteam6\n"); } else if (driver.getCurrentUrl().equals("http://www.armslist.com/")) { WebElement loginButton = driver.findElement(By.linkText("Login")); loginButton.click(); WebElement emailButton = driver.findElement(By.id("email")); emailButton.clear(); emailButton.sendKeys("shrutimundra.20@gmail.com"); WebElement passButton = driver.findElement(By.id("password")); passButton.clear(); passButton.sendKeys("sgpsteam6\n"); } else if (driver.getCurrentUrl().equals("http://www.buyusedguns.net/")) { WebElement loginButton = driver.findElement(By.linkText("Login")); loginButton.click(); WebElement emailButton = driver.findElement(By.name("username")); emailButton.clear(); emailButton.sendKeys("irteam6"); WebElement passButton = driver.findElement(By.name("password")); passButton.clear(); passButton.sendKeys("sgpsteam6\n"); } else if (driver.getCurrentUrl().equals("http://www.cheaperthandirt.com/")) { WebElement loginButton = driver.findElement(By.linkText("Sign In")); loginButton.click(); WebElement emailButton = driver.findElement(By.id("ctl00_ContentPlaceHolderTopLevel_txtEmail")); emailButton.clear(); emailButton.sendKeys("team6ir@gmail.com"); WebElement passButton = driver.findElement(By.id("ctl00_ContentPlaceHolderTopLevel_txtPassword")); passButton.clear(); passButton.sendKeys("sgpsteam6\n"); } else if (driver.getCurrentUrl().equals("http://www.freeclassifieds.com/")) { WebElement loginButton = driver.findElement(By.id("Button1")); loginButton.click(); WebElement emailButton = driver.findElement(By.id("phMain_txtEmail")); emailButton.clear(); emailButton.sendKeys("team6ir@gmail.com"); WebElement passButton = driver.findElement(By.id("phMain_txtPassword")); passButton.clear(); passButton.sendKeys("sgpsteam6\n"); } else if (driver.getCurrentUrl().equals("http://freegunclassifieds.com/")) { WebElement loginButton = driver.findElement(By.id("login_open")); loginButton.click(); WebElement emailButton = driver.findElement(By.id("email")); emailButton.clear(); emailButton.sendKeys("team6ir@gmail.com"); WebElement passButton = driver.findElement(By.id("password")); passButton.clear(); passButton.sendKeys("sgpsteam6\n"); } else if (driver.getCurrentUrl().equals("http://www.gandermountain.com/")) { WebElement loginButton = driver.findElement(By.xpath("//*[@class = 'top-level']")); loginButton.click(); WebElement emailButton = driver.findElement(By.id("header-login-email")); emailButton.clear(); emailButton.sendKeys("team6ir@gmail.com"); WebElement passButton = driver.findElement(By.name("password")); passButton.clear(); passButton.sendKeys("sgpsteam6\n"); } else if (driver.getCurrentUrl().equals("http://www.gunauction.com/")) { //gunauction.com WebElement loginButton = driver.findElement(By.className("login-window")); loginButton.click(); WebElement emailButton = driver.findElement(By.name("EMail")); emailButton.clear(); emailButton.sendKeys("team6ir@gmail.com"); WebElement passButton = driver.findElement(By.name("Password1")); passButton.clear(); passButton.sendKeys("sgpsteam6\n"); } else if (driver.getCurrentUrl().equals("http://www.gunlistings.org/")) { //gunlistings.org WebElement loginButton = driver.findElement(By.linkText("Login")); loginButton.click(); WebElement emailButton = driver.findElement(By.name("email_login")); emailButton.clear(); emailButton.sendKeys("team6ir@gmail.com"); WebElement passButton = driver.findElement(By.name("password")); passButton.clear(); passButton.sendKeys("sgpsteam6\n"); } }
From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.login.LoginHandler8.java
License:Apache License
public void processDriver(WebDriver driver) { URL url;/* ww w. jav a 2 s. c o m*/ InputStream is = null; BufferedReader br; String lineContent; PrintWriter writer = null; String currentURL = null; driver.get(url1); try { writer = new PrintWriter("theFile" + i + ".txt", "UTF-8"); i++; } catch (IOException ex) { System.out.println("Something wrong with the PrintWriter"); } try { url = new URL(url1); is = url.openStream(); br = new BufferedReader(new InputStreamReader(is)); while ((lineContent = br.readLine()) != null && writer != null) { writer.println(lineContent); } } catch (MalformedURLException mue) { mue.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { try { if (is != null) is.close(); } catch (IOException ioe) { } } if (writer != null) { writer.close(); } if (url1.equals("http://www.theoutdoorstrader.com")) { driver.findElement(By.value("loginBar")).click(); driver.findElement(By.id("LoginControl")).sendKeys("will"); driver.findElement(By.id("ctrl_password")).sendKeys("will"); driver.findElement(By.value("Log in")).click(); } currentURL = driver.getCurrentUrl(); try { writer = new PrintWriter("theFile" + i + ".txt", "UTF-8"); i++; } catch (IOException ex) { System.out.println("Something wrong with the PrintWriter"); } try { url = new URL(currentURL); is = url.openStream(); br = new BufferedReader(new InputStreamReader(is)); while ((lineContent = br.readLine()) != null && writer != null) { writer.println(lineContent); } } catch (MalformedURLException mue) { mue.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { try { if (is != null) is.close(); } catch (IOException ioe) { } } if (writer != null) { writer.close(); } driver.quit(); }
From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.login.LoginHandlerUK2.java
License:Apache License
public void processDriver(WebDriver driver) { try {/* w w w . ja va 2 s.c o m*/ if (driver.getCurrentUrl().startsWith("http://abqcareers.careers.adicio.com/jobs/user/login")) { driver.findElement(By.id("auth_email")).sendKeys("csci572hw@gmail.com"); driver.findElement(By.id("auth_password")).sendKeys("lalahaha"); driver.findElement(By.id("submitForm")).click(); } if (driver.getCurrentUrl().startsWith("http://www.hawaiiguntrader.com/login")) { driver.findElement(By.id("login_username")).sendKeys("csci572hw"); driver.findElement(By.id("login_password")).sendKeys("Rg^lW$ual&Ul"); driver.findElement(By.id("login")).click(); } if (driver.getCurrentUrl().startsWith("http://buyusedguns.net/login")) { driver.findElement(By.id("username")).sendKeys("csci572hw"); driver.findElement(By.id("password")).sendKeys("lalahaha"); driver.findElement(By.id("submit")).click(); } if (driver.getCurrentUrl().startsWith("http://freegunclassifieds.com/user/login")) { driver.findElement(By.id("email")).sendKeys("csci572hw@gmail.com"); driver.findElement(By.id("password")).sendKeys("lalahaha"); driver.findElement(By.id("password")).submit(); } if (driver.getCurrentUrl().startsWith("http://floridaguntrade.com/login")) { driver.findElement(By.id("login_username")).sendKeys("csci572hw"); driver.findElement(By.id("login_password")).sendKeys("VDa3pD4OLxti"); driver.findElement(By.id("login")).click(); } if (driver.getCurrentUrl().startsWith("http://www.montanagunclassifieds.com/login")) { driver.findElement(By.name("update_email")).sendKeys("csci572hw@gmail.com"); driver.findElement(By.name("password")).sendKeys("lalahaha"); driver.findElement(By.name("submit")).click(); } if (driver.getCurrentUrl().startsWith("http://www.nationalguntrader.com/main/login")) { driver.findElement(By.id("username")).sendKeys("csci572hw"); driver.findElement(By.id("password")).sendKeys("14630382"); driver.findElement(By.id("password")).submit(); } if (driver.getCurrentUrl().startsWith("https://www.nextechclassifieds.com/myaccounts/login")) { driver.findElement(By.id("id_username")).sendKeys("csci572hw"); driver.findElement(By.id("id_password")).sendKeys("lalahaha"); driver.findElement(By.id("id_password")).submit(); } if (driver.getCurrentUrl().startsWith("http://www.kyclassifieds.com/login")) { driver.findElement(By.id("login_username")).sendKeys("csci572hw"); driver.findElement(By.id("login_password")).sendKeys("lalahaha"); driver.findElement(By.id("login")).submit(); } if ("http://www.kyclassifieds.com/".startsWith(driver.getCurrentUrl())) { driver.findElement(By.id("go")).click(); } if (driver.getCurrentUrl().startsWith("http://www.gunlistings.org")) { driver.findElement(By.name("category")).submit(); } if ("http://www.gunbroker.com/".startsWith(driver.getCurrentUrl())) { new Select(driver.findElement(By.id("Cats"))).selectByIndex(1); driver.findElement(By.id("pbSearch")).click(); } if ("http://www.gandermountain.com/".startsWith(driver.getCurrentUrl())) { driver.findElement(By.id("search_form")).submit(); } } catch (NoSuchElementException e) { System.out.println("MyHandler: " + e.toString()); } }
From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.misc.MiscHandler1.java
License:Apache License
public void processDriver(WebDriver driver) { FirefoxProfile p = new FirefoxProfile(); p.setPreference("webdriver_firefox_port", 8054); String URL = driver.getCurrentUrl(); Site site = this.matches(URL); if (site == null) return;//from ww w. ja v a 2 s.com System.out.println("Processing: " + URL); driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); List<Action> actions = site.getActions(); for (Action action : actions) { String actionType = action.getType(); if (actionType.equals("input")) { WebElement element = findWebElement(action.getBy(), action.getValue(), driver); if (element == null) return; element.sendKeys(action.getKey()); } else if (actionType.equals("click")) { WebElement element = findWebElement(action.getBy(), action.getValue(), driver); if (element == null) return; element.click(); //Wait for a potential new page to load //driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); // driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); } else if (actionType.equals("redirect-append")) { //driver.navigate().to(action.getValue()); //driver.get(action.getValue());//Exactly same as the above driver.get(URL + action.getValue()); //Wait for a potential new page to load /* { Thread.sleep(10000); } catch(Exception e) { e.printStackTrace(); }*/ } driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); } driver.close(); }
From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.MultiplePatterns.CrawlHandler.java
License:Apache License
/** * handles data behind web form, pagination, ajax based interaction for seed urls */// www. j a v a2 s . c om public void processDriver(WebDriver driver) { StringBuffer sBuffer = new StringBuffer(); String htmlpage = "<html><body>"; System.out.println("reading url " + driver.getCurrentUrl()); if (driver.getCurrentUrl().equals("http://www.wikiarms.com/")) { // handling pagination driver.manage().window().maximize(); List<WebElement> anchorTags = driver.findElements(By.xpath("//a")); for (WebElement anchorTag : anchorTags) { htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>"; sBuffer.append(anchorTag.getAttribute("href")); sBuffer.append("\n"); } WebElement ele = driver.findElement(By.xpath("//*[@id='products-table']/div/ul//a[@rel='next']")); for (int i = 0; ele != null; i++) { try { ele.click(); System.out.println(driver.getCurrentUrl()); Thread.sleep(1000); List<WebElement> anchorTags2 = driver.findElements(By.xpath("//*[@id='products-table']//a")); for (WebElement anchorTag2 : anchorTags2) { htmlpage += "<a href='" + anchorTag2.getAttribute("href") + "'>test</a>"; sBuffer.append(anchorTag2.getAttribute("href")); sBuffer.append("\n"); } ele = driver.findElement(By.xpath("//*[@id='products-table']/div/ul//a[@rel='next']")); } catch (Exception e) { ele = null; } } htmlpage += "</body></html>"; System.out.println("html is " + htmlpage); JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("document.body.innerHTML=arguments[0]", htmlpage); //return htmlpage; } else if (driver.getCurrentUrl().equals("http://www.ksl.com/")) { // handling pagination and search guns driver.manage().window().maximize(); WebElement loginWindow = driver .findElement(By.xpath("//*[@id='kslHeader']/div/div[1]/div/div[4]/a/span")); loginWindow.click(); WebElement username = driver.findElement(By.className("ksl-header-search__input")); username.sendKeys("guns"); WebElement loginBtn = driver .findElement(By.xpath("//*[@id='kslHeader']/div/div[1]/div/div[4]/div/form/button")); loginBtn.click(); System.out.println(driver.getCurrentUrl()); List pages = driver.findElements( By.xpath("//*[@id='___gcse_0']/div/div/div/div[5]/div[2]/div/div/div[2]/div[11]//div")); int size = pages.size(); List<WebElement> anchorTags = driver.findElements(By.xpath("//a")); for (WebElement anchorTag : anchorTags) { htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>"; sBuffer.append(anchorTag.getAttribute("href")); sBuffer.append("\n"); } System.out.println(size); if (size > 0) { for (int i = 2; i < size; i++) { System.out.println("inside for loop"); try { driver.findElement(By.xpath( "//*[@id='___gcse_0']/div/div/div/div[5]/div[2]/div/div/div[2]/div[11]/div/div[" + i + "]")) .click(); Thread.sleep(1000); List<WebElement> anchorTags2 = driver .findElements(By.xpath("/html/body/div[1]/div[2]/div[2]/div[3]/div/div[2]//a")); for (WebElement anchorTag2 : anchorTags2) { htmlpage += "<a href='" + anchorTag2.getAttribute("href") + "'>test</a>"; sBuffer.append(anchorTag2.getAttribute("href")); sBuffer.append("\n"); } } catch (Exception e) { } } } htmlpage += "</body></html>"; JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("document.body.innerHTML=arguments[0]", htmlpage); System.out.println(htmlpage); } else if (driver.getCurrentUrl().equals("http://www.kyclassifieds.com/")) { // handling pagination and search guns System.out.println("final else loop"); driver.manage().window().maximize(); WebElement searchField = driver.findElement(By.xpath("//*[@id='s']")); searchField.sendKeys("guns"); WebElement searchButton = driver.findElement(By.xpath("//*[@id='go']")); searchButton.click(); System.out.println(driver.getCurrentUrl()); List<WebElement> anchorTags = driver.findElements(By.xpath("//a")); for (WebElement anchorTag : anchorTags) { htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>"; sBuffer.append(anchorTag.getAttribute("href")); sBuffer.append("\n"); } WebElement ele = driver.findElement(By.className("next page-numbers")); for (int i = 0; ele != null; i++) { try { ele.click(); System.out.println(driver.getCurrentUrl()); Thread.sleep(1000); List<WebElement> anchorTags2 = driver .findElements(By.xpath("/html/body/div/div[4]/div/div/div[2]//a")); for (WebElement anchorTag2 : anchorTags2) { htmlpage += "<a href='" + anchorTag2.getAttribute("href") + "'>test</a>"; sBuffer.append(anchorTag2.getAttribute("href")); sBuffer.append("\n"); } ele = driver.findElement(By.className("next page-numbers")); } catch (Exception e) { ele = null; } } htmlpage += "</body></html>"; JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("document.body.innerHTML=arguments[0]", htmlpage); System.out.println(htmlpage); } else if (driver.getCurrentUrl().equals("http://www.iguntrade.com/")) { // handling paginations List<WebElement> anchorTags = driver.findElements(By.xpath("//a")); for (WebElement anchorTag : anchorTags) { htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>"; sBuffer.append(anchorTag.getAttribute("href")); sBuffer.append("\n"); } WebElement ele = driver.findElement(By.className("searchPaginationNext list-last")); for (int i = 0; ele != null; i++) { try { ele.click(); System.out.println(driver.getCurrentUrl()); Thread.sleep(1000); List<WebElement> anchorTags2 = driver.findElements(By.xpath("//*[@id='main']//a")); for (WebElement anchorTag2 : anchorTags2) { htmlpage += "<a href='" + anchorTag2.getAttribute("href") + "'>test</a>"; sBuffer.append(anchorTag2.getAttribute("href")); sBuffer.append("\n"); } ele = driver.findElement(By.className("searchPaginationNext list-last")); } catch (Exception e) { ele = null; } } htmlpage += "</body></html>"; JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("document.body.innerHTML=arguments[0]", htmlpage); System.out.println(htmlpage); } else if (driver.getCurrentUrl().equals("http://www.gowilkes.com/")) { // handling search guns WebElement searchField = driver.findElement(By.xpath("//*[@id='search_box']")); searchField.sendKeys("guns"); WebElement classifiedRadioBtn = driver .findElement(By.xpath("//*[@id='search_container']/form/div/div[5]/input")); classifiedRadioBtn.click(); WebElement searchButton = driver .findElement(By.xpath("//*[@id='search_container']/form/table/tbody/tr/td[2]/span")); searchButton.click(); System.out.println(driver.getCurrentUrl()); List<WebElement> anchorTags = driver.findElements(By.xpath("//a")); for (WebElement anchorTag : anchorTags) { htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>"; sBuffer.append(anchorTag.getAttribute("href")); sBuffer.append("\n"); } List<WebElement> anchorTagGuns = driver .findElements(By.xpath("//*[@id='content']/tbody/tr/td[1]/div[2]/table")); for (WebElement anchorTag : anchorTagGuns) { htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>"; sBuffer.append(anchorTag.getAttribute("href")); sBuffer.append("\n"); } htmlpage += "</body></html>"; JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("document.body.innerHTML=arguments[0]", htmlpage); System.out.println(htmlpage); } else if (driver.getCurrentUrl().equals("http://www.floridagunclassifieds.com/")) { // handling scrolling of page for (int i = 0; i < 20; i++) { JavascriptExecutor jse = (JavascriptExecutor) driver; jse.executeScript("window.scrollBy(0,250)", ""); } List<WebElement> anchorTags = driver.findElements(By.xpath("//a")); for (WebElement anchorTag : anchorTags) { htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>"; sBuffer.append(anchorTag.getAttribute("href")); sBuffer.append("\n"); } htmlpage += "</body></html>"; JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("document.body.innerHTML=arguments[0]", htmlpage); System.out.println(htmlpage); } else if (driver.getCurrentUrl().equals("http://www.elpasoguntrader.com/")) { // handling pagination List<WebElement> anchorTags = driver.findElements(By.xpath("//a")); for (WebElement anchorTag : anchorTags) { htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>"; sBuffer.append(anchorTag.getAttribute("href")); sBuffer.append("\n"); } WebElement nextField = driver .findElement(By.xpath("//*[@id='dj-classifieds']/div/div/div//a[@title='Next']")); for (int i = 0; nextField.isEnabled(); i++) { try { nextField.click(); Thread.sleep(1000); List<WebElement> anchors = driver.findElements(By.xpath("//a")); for (WebElement anchorTag : anchors) { htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>"; sBuffer.append(anchorTag.getAttribute("href")); sBuffer.append("\n"); } nextField = driver .findElement(By.xpath("//*[@id='dj-classifieds']/div/div/div//a[@title='Next']")); } catch (Exception e) { } } htmlpage += "</body></html>"; JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("document.body.innerHTML=arguments[0]", htmlpage); System.out.println(htmlpage); } else if (driver.getCurrentUrl().equals("http://www.classifiednc.com/")) { // handling gun link tap in left panel and pagination WebElement forSale = driver.findElement(By.xpath("//*[@id='body_con']/div[1]/div/div[2]/div[5]")); forSale.click(); WebElement gunList = driver.findElement(By.xpath("//*[@id='catlist']/div[16]/a")); gunList.click(); boolean nextBtn = driver .findElement(By.xpath( "//*[@id='classifiedsContainer']/table/tbody/tr/td[2]/table[2]/tbody/tr/td/div/div")) .isDisplayed(); for (int i = 0; nextBtn != false; i++) { try { Thread.sleep(1000); List<WebElement> anchorTags = driver.findElements( By.xpath("//*[@id='classifiedsContainer']/table/tbody/tr/td[2]/table[1]//a")); for (WebElement anchorTag : anchorTags) { htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>"; sBuffer.append(anchorTag.getAttribute("href")); sBuffer.append("\n"); } driver.findElement(By.xpath( "//*[@id='classifiedsContainer']/table/tbody/tr/td[2]/table[2]/tbody/tr/td/div/div")) .click(); nextBtn = driver.findElement(By.xpath( "//*[@id='classifiedsContainer']/table/tbody/tr/td[2]/table[2]/tbody/tr/td/div/div")) .isDisplayed(); } catch (Exception e) { } } htmlpage += "</body></html>"; JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("document.body.innerHTML=arguments[0]", htmlpage); System.out.println(htmlpage); } else if (driver.getCurrentUrl().equals("http://www.wantaddigest.com/")) { // handling search field WebElement forSale = driver.findElement(By.xpath("//*[@id='country']")); forSale.sendKeys("guns"); WebElement nextBtn = driver.findElement(By.xpath("//*[@id='left-home']/form/input[2]")); try { nextBtn.click(); Thread.sleep(1000); List<WebElement> anchorTags = driver.findElements(By.xpath("//*[@id='middle']//a")); for (WebElement anchorTag : anchorTags) { htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>"; sBuffer.append(anchorTag.getAttribute("href")); sBuffer.append("\n"); } } catch (Exception e) { } htmlpage += "</body></html>"; JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("document.body.innerHTML=arguments[0]", htmlpage); System.out.println(htmlpage); } else if (driver.getCurrentUrl().equals("http://www.nextechclassifieds.com/")) { // handling search field WebElement searchField = driver.findElement(By.xpath("//*[@id='nav-search-input']")); searchField.sendKeys("guns"); WebElement searchBtn = driver.findElement(By.xpath("//*[@id='search-btn']")); searchBtn.click(); boolean nextBtn = driver .findElement(By.xpath("//*[@id='site-wrapper']/div/div[2]/div/div[2]/ul[1]/li[8]/a")) .isEnabled(); for (int i = 0; nextBtn != false; i++) { try { Thread.sleep(1000); List<WebElement> anchorTags = driver .findElements(By.xpath("//*[@id='gallery-container']/ul//a")); for (WebElement anchorTag : anchorTags) { htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>"; sBuffer.append(anchorTag.getAttribute("href")); sBuffer.append("\n"); } driver.findElement(By.xpath("//*[@id='site-wrapper']/div/div[2]/div/div[2]/ul[1]/li[8]/a")) .click(); nextBtn = driver .findElement(By.xpath("//*[@id='site-wrapper']/div/div[2]/div/div[2]/ul[1]/li[8]/a")) .isEnabled(); } catch (Exception e) { } } htmlpage += "</body></html>"; JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("document.body.innerHTML=arguments[0]", htmlpage); System.out.println(htmlpage); } else if (driver.getCurrentUrl().equals("http://www.theoutdoorstrader.com/")) { // handling pagination and ajax interaction driver.manage().window().maximize(); WebElement searchField = driver.findElement(By.xpath("//*[@id='QuickSearchQuery']")); searchField.click(); searchField.sendKeys("guns"); WebElement submitBtn = driver.findElement(By.xpath("//*[@id='QuickSearch']/form/div[2]/dl/dd/input")); submitBtn.click(); List<WebElement> anchorTags = driver.findElements(By.xpath("//*[@id='content']/div/div//a")); for (WebElement anchorTag : anchorTags) { htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>"; sBuffer.append(anchorTag.getAttribute("href")); sBuffer.append("\n"); } boolean nextBtn = driver.findElement(By.linkText("Next >")).isDisplayed(); for (int i = 0; nextBtn != false; i++) { try { Thread.sleep(1000); driver.findElement(By.linkText("Next >")).click(); List<WebElement> anchors = driver.findElements(By.xpath("//*[@id='content']/div/div//a")); for (WebElement anchorTag : anchors) { htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>"; sBuffer.append(anchorTag.getAttribute("href")); sBuffer.append("\n"); } nextBtn = driver.findElement(By.linkText("Next >")).isDisplayed(); } catch (Exception e) { nextBtn = false; } } htmlpage += "</body></html>"; JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("document.body.innerHTML=arguments[0]", htmlpage); System.out.println(htmlpage); } else if (driver.getCurrentUrl().equals("http://www.arguntrader.com/")) { // handling web form data driver.manage().window().maximize(); WebElement searchField = driver .findElement(By.xpath("//*[@id='page-header']/div[2]/div/ul[2]/li[3]/a")); searchField.click(); WebElement usernameField = driver.findElement(By.xpath("//*[@id='username']")); usernameField.sendKeys("testing"); WebElement passwordField = driver.findElement(By.xpath("//*[@id='password']")); passwordField.sendKeys("usccsci572"); WebElement loginBtn = driver .findElement(By.xpath("//*[@id='login']/div[1]/div/div/fieldset/dl[4]/dd/input[3]")); loginBtn.click(); try { Thread.sleep(5000); List<WebElement> anchorTags = driver.findElements(By.xpath("//a")); for (WebElement anchorTag : anchorTags) { htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>"; sBuffer.append(anchorTag.getAttribute("href")); sBuffer.append("\n"); } } catch (Exception e) { e.printStackTrace(); } } else { System.out.println("else loop"); } writeURLToFile(sBuffer); }
From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.MultiplePatterns.CS572LoginAndClickHandler.java
License:Apache License
public void processDriver(WebDriver driver) { try {/*w w w. j av a 2 s. c om*/ Configuration conf = NutchConfiguration.create(); driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); currentURL = driver.getCurrentUrl(); if (currentURL.contains("buyusedguns") && (currentURL.contains("login") || currentURL.contains("Login"))) { System.out.println("[Interactiveselenium]: Interactive login \"" + currentURL + "\""); loginScriptIDIDID(conf, driver, "username", "password", "submit", false); } else if (currentURL.contains("gunlistings") && (currentURL.contains("login") || currentURL.contains("Login"))) { System.out.println("[Interactiveselenium]: Interactive login \"" + currentURL + "\""); loginScriptNameNameXPath(conf, driver, "email_login", "password", "//input[@value='Login']", true); } else if (currentURL.contains("recycler") && (currentURL.contains("login") || currentURL.contains("Login"))) { System.out.println("[Interactiveselenium]: Interactive login \"" + currentURL + "\""); loginScriptIDIDXPath(conf, driver, "login", "password", "//input[@value='Login']", true); } else if (currentURL.contains("slickguns") && (currentURL.contains("user"))) { System.out.println("[Interactiveselenium]: Interactive login \"" + currentURL + "\""); loginScriptIDIDID(conf, driver, "edit-name", "edit-pass", "edit-submit", false); // } else if (currentURL.contains("shooting.org") && (currentURL.contains("login"))) { System.out.println("[Interactiveselenium]: Interactive login \"" + currentURL + "\""); loginScriptIDIDXPath(conf, driver, "UserEmail", "UserPassword", "//input[@value='Sign in']", true); // } else if (currentURL.contains("wantaddigest.com") && (currentURL.contains("LogOn"))) { System.out.println("[Interactiveselenium]: Interactive login \"" + currentURL + "\""); loginScriptIDIDXPath(conf, driver, "Email", "Password", "//input[@value='Sign in']", true); // } else if (currentURL.contains("floridagunclassifieds.com") && (currentURL.contains("login"))) { System.out.println("[Interactiveselenium]: Interactive login \"" + currentURL + "\""); loginScriptIDIDID(conf, driver, "login_username", "login_password", "login", false); // } else if (currentURL.contains("gunidaho.com") && (currentURL.contains("login"))) { System.out.println("[Interactiveselenium]: Interactive login \"" + currentURL + "\""); loginScriptIDIDXPath(conf, driver, "User_email", "User_password", "//input[@value='Sign in']", true); // } else if (currentURL.equals("http://www.iwanna.com/")) { System.out.println("[Interactiveselenium]: Interactive login \"" + currentURL + "\""); loginScriptIDIDID(conf, driver, "welcome_username", "welcome_password", "welcome_login", false); // } else if (currentURL.contains("carolinabargaintrader.net/index.php") && currentURL.contains("a=10")) { System.out.println("[Interactiveselenium]: Interactive login \"" + currentURL + "\""); loginScriptIDIDXPath(conf, driver, "username", "password", "//input[@value='Login']", false); // } else if (currentURL.contains("floridaguntrader.com/index.php") && currentURL.contains("a=10")) { System.out.println("[Interactiveselenium]: Interactive login \"" + currentURL + "\""); loginScriptIDIDXPath(conf, driver, "username", "password", "//input[@value='Login >>']", false); // } else if (currentURL.contains("hawaiiguntrader.com") && currentURL.contains("login")) { System.out.println("[Interactiveselenium]: Interactive login \"" + currentURL + "\""); loginScriptIDIDID(conf, driver, "login_username", "login_password", "login", false); // } else if (currentURL.contains("theoutdoorstrader.com")) { System.out.println("[Interactiveselenium]: Interactive login \"" + currentURL + "\""); WebElement username1 = driver.findElement(By.id("LoginControl")); WebElement password1 = driver.findElement(By.id("ctrl_password")); WebElement username2 = driver.findElement(By.id("ctrl_pageLogin_login")); WebElement password2 = driver.findElement(By.id("ctrl_pageLogin_password")); WebElement submitElement = driver.findElement(By.xpath("//input[@value='Log in']")); if (username1 != null && password1 != null && submitElement != null) { loginScriptIDIDXPath(conf, driver, "LoginControl", "ctrl_password", "//input[@value='Log in']", false); } else if (username2 != null && password2 != null && submitElement != null) { loginScriptIDIDXPath(conf, driver, "ctrl_pageLogin_login", "ctrl_pageLogin_password", "//input[@value='Log in']", false); } // } else if (currentURL.contains("zidaho.com/index.php") && currentURL.contains("a=10")) { System.out.println("[Interactiveselenium]: Interactive login \"" + currentURL + "\""); loginScriptIDIDXPath(conf, driver, "username", "password", "//input[@value='Login >>']", false); // } else if ((currentURL.equals("http://www.budsgunshop.com/catalog/index.php")) || (currentURL.equals("http://tennesseegunexchange.com/")) || (currentURL.contains("gunidaho.com")) || (currentURL.contains("hawaiiguntrader.com")) || (currentURL.contains("slickguns.com")) || (currentURL.contains("buyusedguns.net")) ) { System.out.println("[Interactiveselenium]: Interactive click \"" + currentURL + "\""); // Click link and record dynamic content clickAllAjaxLinks(conf, driver); } else { System.out.println("[Interactiveselenium]: Selenium only \"" + currentURL + "\""); } } catch (Exception e) { LOG.info(StringUtils.stringifyException(e)); } }
From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.MultiplePatterns.CS572LoginAndClickHandler.java
License:Apache License
private void loginActionScript(WebDriver driver, WebElement usernameElement, WebElement passwordElement, WebElement submitElement, boolean isEmail) { if (usernameElement != null && passwordElement != null && submitElement != null) { if (isEmail) { usernameElement.sendKeys("cs572testtest@gmail.com"); } else if (driver.getCurrentUrl().contains("carolinabargaintrader.net")) { usernameElement.sendKeys("cs572testtes"); } else {/*from w w w . j a v a 2s . co m*/ usernameElement.sendKeys("cs572testtest"); } if (driver.getCurrentUrl().contains("recycler.com")) { passwordElement.sendKeys("s572@testtest"); } else { passwordElement.sendKeys("Cs572@test"); } submitElement.click(); try { Thread.sleep(2300); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } recordHtmlBodyWithDynamicChange(driver); if (refreshFlag) { refreshFlag = false; // refresh page to refresh handler to the un-touched state driver.get(currentURL); } JavascriptExecutor jsx = (JavascriptExecutor) driver; Iterator<String> itr = accumulatedDataArrayList.iterator(); while (itr.hasNext()) { String accumulatedData = itr.next(); try { jsx.executeScript("document.body.innerHTML = document.body.innerHTML + " + "'" + accumulatedData + "'" + ";"); } catch (Exception ee) { System.out.println(ee); } } // System.exit(0); } }