List of usage examples for org.openqa.selenium WebDriver manage
Options manage();
From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.login.LoginHandlerUK3.java
License:Apache License
public boolean shouldProcessURL(String URL) { WebDriver driver = new FirefoxDriver(); // to resolve selinum issue with Firefox driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS); try {/*from w w w .j av a 2s . c o m*/ Thread.sleep(10000); } catch (Exception e) { Http.LOG.error("error in try dishant " + e); } Http.LOG.error("trigger" + URL); if (URL.equals("http://www.arguntrader.com")) { Http.LOG.error("in" + URL); // login for arguntrader.com driver.get("http://www.arguntrader.com/ucp.php?mode=login"); WebElement query = driver.findElement(By.id("username")); query.sendKeys("testtest"); query = driver.findElement(By.id("password")); query.sendKeys("password123"); driver.findElement(By.name("login")).click(); } else if (URL.equals("http://www.iguntrade.com")) { Http.LOG.error("in" + URL); // pagination for iguntrade.com driver.get("http://www.iguntrade.com/index.php?page=search"); List<WebElement> allpages = driver.findElements(By.xpath("//div[@class='paginate']//a")); for (int i = 0; i <= (allpages.size()); i++) { allpages.get(i).click(); } } else if (URL.contains("http://www.zidaho.com/category")) { Http.LOG.error("in" + URL); // pagination for zidaho.com List<WebElement> allpages = driver .findElements(By.xpath("//ul[@class='pagination browsing_result_page_links']//a")); for (int i = 0; i <= (allpages.size()); i++) { allpages.get(i).click(); } } return true; }
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 w w w. j a 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 *//*w ww . j a v a2s.com*/ 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 ww.j av a 2 s. co m*/ 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.Pagination.PaginationHandler18.java
License:Apache License
public void argunTrader(WebDriver driver) { String URL = driver.getCurrentUrl(); driver.manage().window().maximize(); //To click the login button in the home screen if (URL.equals("http://www.arguntrader.com/")) { driver.findElement(By.xpath("/html/body//li[@class='icon-logout']/a")).click(); }/*from w w w . j av a 2 s. c om*/ //To enter the login details WebElement username = driver.findElement(By.id("username")); username.sendKeys("char12"); WebElement password = driver.findElement(By.id("password")); password.sendKeys("charan"); //To click the login button driver.findElement(By.xpath("/html/body//dd/input[@class='button1']")).click(); }
From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.Pagination.PaginationHandler18.java
License:Apache License
public void vci_classifieds(WebDriver driver) { driver.manage().window().maximize(); //to hover over the Ad Category button and click it driver.findElement(By.xpath("/html/body//a[@id='categorylink']")).click(); //Hover over to firearm category and click Handguns WebElement element1 = driver.findElement(By.xpath("/html/body/div[3]/div/div/div[3]/ul/li[4]/a")); JavascriptExecutor executor = (JavascriptExecutor) driver; executor.executeScript("arguments[0].click();", element1); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); List<WebElement> w1 = driver.findElements(By.xpath("html/body//div[@id='adlist']/table[3]//a")); for (WebElement ele : w1) { String str1;//from ww w.j a v a2s . c o m str1 = ele.getAttribute("href"); int begin = str1.indexOf("(") + 2; if (begin < 0) continue; int end = str1.indexOf(")") - 1; if (end < 0) continue; String adId = str1.substring(begin, end); String url = "https://www.vci-classifieds.com/a-getad.php?id=" + adId; executor.executeScript("$.get(arguments[0], function(data) { $('#fb-root').html(data); } );", url); driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); } element1 = driver.findElement(By.xpath("/html/body/div[3]/div/div/div[3]/ul/li[5]/a")); executor.executeScript("arguments[0].click();", element1); }
From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.Pagination.PaginationHandler18.java
License:Apache License
public void processDriver(WebDriver driver) { String url = driver.getCurrentUrl(); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); // Charan/* w ww. jav a 2 s .co m*/ if (url.matches("^http://([a-zA-Z0-9]+.)*armslist.com/classifieds/\\S*")) { processArmsList(driver); } if (url.matches("^http://([a-zA-Z0-9]+.)*impactguns.com/\\S+.aspx")) { processImpactGuns(driver); } if (url.matches("^http://([a-zA-Z0-9]+.)*iwanna.com/\\S*")) { processIwana(driver); } if (url.matches("^http://([a-zA-Z0-9]+.)*budsgunshop.com/\\S*")) { processBudgunshop(driver); } if (url.matches("^http://([a-zA-Z0-9]+.)*buyusedguns.net/\\S*")) { processBuyusedguns(driver); } if (url.matches("^http://([a-zA-Z0-9]+.)*cheaperthandirt.com/\\S*")) { processCheaperthandirt(driver); } if (url.matches("^http://([a-zA-Z0-9]+.)*davidsonsinc.com/\\S*") && processDavidSonic) { int size = driver.findElements(By.xpath("html/body//div[9]/a")).size(); if (size > 0) { driver.findElement(By.xpath("html/body//div[9]/a")).click(); } processDavidSonic = false; } //charan ends //sharan if (url.matches("^http://([a-zA-Z0-9]+.)*boards.4chan.org/k/\\S*")) { process4chan(driver); } if (url.matches("^http://([a-zA-Z0-9]+.)*tennesseegunexchange.com/\\S*")) { processtenness(driver); } if (url.matches( "^http://([a-zA-Z0-9]+.)*zidaho.com/category/(\\S*gun\\S*)|(\\S*Rifle\\S*)|(\\S*Ammunition\\S*)|(\\S*arms\\S*)|(\\S*Black-Powder\\S*)")) { processzidaho(driver); } if (url.matches("^http://([a-zA-Z0-9]+.)*dallasguns.com/\\S*")) { processdallasguns(driver); } if (url.matches("^http://([a-zA-Z0-9]+.)*elpasoguntrader.com/\\S*")) { processelpaso(driver); } if (url.matches("^http://([a-zA-Z0-9]+.)*floridaguntrader.com/\\S*")) { processfloridagun(driver); } if (url.matches("^http://([a-zA-Z0-9]+.)*iguntrade.com/\\S*")) { processigun(driver); } if (url.matches("^http://([a-zA-Z0-9]+.)*gandermountain.com/guns/\\S*")) { processgander(driver); } // sharan ends // rakshith if (url.matches("^http://([a-zA-Z0-9]+.)*gunlistings.org/ohio-gun-classifieds/\\S*")) { processGunListingsOhio(driver); } if (url.matches("^http://([a-zA-Z0-9]+.)*wikiarms.com/\\S*")) { processWikiArms(driver); } if (url.matches("^http://([a-zA-Z0-9]+.)*nextechclassifieds.com/\\S*")) { processNextechClassifieds(driver); } if (url.matches("^http://([a-zA-Z0-9]+.)*shooterswap.com/\\S*")) { processShooterSwap(driver); } if (url.matches("^http://([a-zA-Z0-9]+.)*slickguns.com/\\S*")) { processSlickGuns(driver); } if (url.matches("^http://([a-zA-Z0-9]+.)*gunlistings.org/\\S*")) { processGunListings(driver); } // rakshith ends // Mithun if (url.matches("^http://([a-zA-Z0-9]+.)*arguntrader.com/\\S*")) { argunTrader(driver); } if (url.matches("^http://([a-zA-Z0-9]+.)*vci-classifieds.com/\\S*")) { vci_classifieds(driver); } // Mithun ends }
From source file:gov.nasa.jpl.nutch.phantomjs.PhantomJSWebClient.java
License:Apache License
public static WebDriver getDriverForPage(String url) { long pageLoadTimout = 3; DesiredCapabilities caps = new DesiredCapabilities(); caps.setJavascriptEnabled(true);/*from w ww .j a va 2 s .co m*/ caps.setCapability("takesScreenshot", false); WebDriver driver = null; try { driver = new PhantomJSDriver(caps); driver.manage().timeouts().pageLoadTimeout(pageLoadTimout, TimeUnit.SECONDS); driver.get(url); } catch (Exception e) { if (e instanceof TimeoutException) { System.out.println("PhantomJS WebDriver: Timeout Exception: Capturing whatever loaded so far..."); return driver; } cleanUpDriver(driver); throw new RuntimeException(e); } return driver; }
From source file:gov.nih.nci.firebird.commons.selenium2.util.FileDownloadUtils.java
License:Open Source License
private static void setupCookies(DefaultHttpClient client, WebDriver driver) { CookieStore cookieStore = new BasicCookieStore(); for (Cookie webDriverCookie : driver.manage().getCookies()) { cookieStore.addCookie(translateCookie(webDriverCookie)); }/*w w w. jav a 2 s .co m*/ client.setCookieStore(cookieStore); }
From source file:imagedownload.Downloader.java
public void download() { System.out.println((new Date()).toString()); WebDriver driver = new ChromeDriver(); WebDriver.Window win = driver.manage().window(); // get the full screen size (exculde desktop toolbar) win.maximize();/*from w w w . j a v a2 s. c o m*/ int screenHeight = win.getSize().getHeight(); int screenWidth = win.getSize().getWidth(); System.out.println("Screen: " + screenHeight + "*" + screenWidth); // set browser size and position it to bottom right win.setSize(new Dimension(browserWidth, browserHeight)); System.out.println("Browser: " + win.getSize().getHeight() + "*" + win.getSize().getWidth()); win.setPosition(new Point(screenWidth - browserWidth, screenHeight - browserHeight)); // position the browser outside of windows if (hide) { win.setPosition(new Point(screenWidth, screenHeight)); } String page = firstPage; boolean hasNextPage = true; int pageCnt = 0; while (hasNextPage && pageCnt < pageLimit) { pageCnt++; if (visitedPages.get(page) != null) { System.out.println("Looped back. Quit download."); break; } visitedPages.put(page, page); driver.get(page); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); hasNextPage = false; if (pagination) { // if no xpath configured, default search all <a> hyperlinks if (xpath == null || xpath.trim().equals("")) { xpath = determineNextPage(driver); } if (xpath != null && !xpath.trim().equals("")) { page = ""; System.out.println("Xpath: " + xpath); List<WebElement> checkList = driver.findElements(By.xpath(xpath)); for (WebElement elm : checkList) { String text = elm.getAttribute("innerHTML"); for (String t : next) { if (text.equals(t)) { hasNextPage = true; page = elm.getAttribute("href"); break; } } } System.out.println("Next page: " + hasNextPage + ", " + page); } } List<WebElement> imgList = driver.findElements(By.tagName("img")); List<String> filteredList = new ArrayList<String>(); for (WebElement img : imgList) { if (img.getAttribute("src") == null) { continue; } if (duplicateFilter) { if (savedImages.get(img.getAttribute("src")) != null) { continue; } } if (minSizeFilter) { if (img.getSize().getHeight() < minHeight || img.getSize().getWidth() < minWidth) { continue; } } filteredList.add(img.getAttribute("src").trim()); } int cnt = 0; InputStream imgIn = null; OutputStream imgOut = null; for (String location : filteredList) { cnt++; try { String[] urlArr = location.split("\\/"); String[] nameArr = urlArr[urlArr.length - 1].split("\\."); String ext = nameArr[nameArr.length - 1]; String filePath = config.getProperty("output.folder") + config.getProperty("output.namePrefix") + "_" + pageCnt + "_" + cnt + "." + ext; System.out.println("File location: " + location); System.out.println("File name: " + urlArr[urlArr.length - 1]); System.out.println("File ext: " + nameArr[nameArr.length - 1]); System.out.println("Output: " + filePath); driver.get(location); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); WebElement image = driver.findElement(By.tagName("img")); System.out.println("Image element: " + image.getAttribute("src")); AutoSave.save(driver, image, filePath); savedImages.put(location, location); } finally { try { if (imgIn != null) { imgIn.close(); } if (imgOut != null) { imgOut.close(); } } catch (IOException ex) { Logger.getLogger(Downloader.class.getName()).log(Level.SEVERE, null, ex); } } } } driver.quit(); System.out.println((new Date()).toString()); }