Example usage for org.openqa.selenium WebDriver findElements

List of usage examples for org.openqa.selenium WebDriver findElements

Introduction

In this page you can find the example usage for org.openqa.selenium WebDriver findElements.

Prototype

@Override
List<WebElement> findElements(By by);

Source Link

Document

Find all elements within the current page using the given mechanism.

Usage

From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.PageNavigation.PageNavigationUK2.java

License:Apache License

public void processDriver(WebDriver driver) {
    try {/*from   w w w .  java 2s.  com*/
        String accumulatedData = driver.findElement(By.tagName("body")).getAttribute("innerHTML");
        Configuration conf = NutchConfiguration.create();
        new WebDriverWait(driver, conf.getLong("libselenium.page.load.delay", 3));
        //handle ajax content
        List<WebElement> atags = driver.findElements(By.tagName("a"));
        int numberofajaxlinks = atags.size();
        for (int i = 0; i < numberofajaxlinks; i++) {
            if (atags.get(i).getAttribute("href") != null
                    && atags.get(i).getAttribute("href").equals("javascript:void(null);")) {
                atags.get(i).click();
                if (i == numberofajaxlinks - 1) {
                    //append everything to the driver in the last round
                    JavascriptExecutor jsx = (JavascriptExecutor) driver;
                    jsx.executeScript(
                            "document.body.innerHTML=document.body.innerHTML " + accumulatedData + ";");
                    continue;
                }
                accumulatedData += driver.findElement(By.tagName("body")).getAttribute("innerHTML");
                //refreshing the handlers as the page was interacted with
                driver.navigate().refresh();
                new WebDriverWait(driver, conf.getLong("libselenium.page.load.delay", 3));
                atags = driver.findElements(By.tagName("a"));
            }
        }
        //handle content behind a form
        List<WebElement> inputTags = driver.findElements(By.tagName("input"));
        int numberOfInput = inputTags.size();
        for (int i = 0; i < numberOfInput; i++) {
            if (inputTags.get(i).getAttribute("type") != null
                    && inputTags.get(i).getAttribute("type").equals("text")) {
                //take the first text input as the search input
                inputTags.get(i).sendKeys("weapon");
                inputTags.get(i).submit();
                accumulatedData += driver.findElement(By.tagName("body")).getAttribute("innerHTML");
                JavascriptExecutor jsxInput = (JavascriptExecutor) driver;
                //append the data to the driver
                jsxInput.executeScript(
                        "document.body.innerHTML=document.body.innerHTML " + accumulatedData + ";");
                break;
            }
        }

    } 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 processArmsList(WebDriver driver) {
    int agreeSize = 0;
    agreeSize = driver.findElements(By.xpath("/html//div[@class='ui-dialog-buttonset']/button[1]")).size();
    if (agreeSize > 0) {
        WebElement iAgree = driver.findElement(By.xpath("/html//div[@class='ui-dialog-buttonset']/button[1]"));
        iAgree.click();/*from w w w .j a  v  a 2s.c o m*/
    }
    int size = driver.findElements(By.xpath("html/body//div[@class='pager']//li[@class='next']/a")).size();
    if (size > 0) {
        String str1 = "<html><body><p>";
        while (size > 0) {
            List<WebElement> ele = driver.findElements(By.xpath("html/body//a"));
            for (WebElement we : ele) {
                str1 += "<a href='" + (String) we.getAttribute("href") + "'>" + (String) we.getAttribute("href")
                        + "</a><br>";
            }
            size = driver.findElements(By.xpath("html/body//div[@class='pager']//li[@class='next']/a")).size();
            if (size > 0) {
                driver.findElement(By.xpath("html/body//div[@class='pager']//li[@class='next']/a")).click();
            }
        }
        str1 += "</p></body></html>";
        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript("document.body.innerHTML=arguments[0]", str1);
    }
}

From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.Pagination.PaginationHandler18.java

License:Apache License

public void processImpactGuns(WebDriver driver) {
    if (impactGunList.contains(driver.getCurrentUrl()))
        return;/*from   ww w  .  j a va  2s  . c  o  m*/
    impactGunList.add(driver.getCurrentUrl());
    WebElement nextBut;
    int size = driver
            .findElements(By.xpath(
                    "html/body//a[@id='ctl00_ctl00_MainContent_uxCategory_uxCategoryProductList_TopNextLink']"))
            .size();
    if (size > 0) {
        String str1 = "<html><body><p>";
        while (size > 0) {
            List<WebElement> ele = driver.findElements(By.xpath("html/body//a"));
            for (WebElement we : ele) {
                str1 += "<a href='" + (String) we.getAttribute("href") + "'>" + (String) we.getAttribute("href")
                        + "</a><br>";
            }
            size = driver.findElements(By.xpath(
                    "html/body//a[@id='ctl00_ctl00_MainContent_uxCategory_uxCategoryProductList_TopNextLink']"))
                    .size();
            if (size > 0) {
                nextBut = driver.findElement(By.xpath(
                        "html/body//a[@id='ctl00_ctl00_MainContent_uxCategory_uxCategoryProductList_TopNextLink']"));
                String disabledText = nextBut.getAttribute("disabled");
                if (disabledText == null)
                    driver.findElement(By.xpath(
                            "html/body//a[@id='ctl00_ctl00_MainContent_uxCategory_uxCategoryProductList_TopNextLink']"))
                            .click();
                else
                    break;
            }
        }
        str1 += "</p></body></html>";
        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript("document.body.innerHTML=arguments[0]", str1);
    }
}

From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.Pagination.PaginationHandler18.java

License:Apache License

public void processIwana(WebDriver driver) {
    int size = driver.findElements(By.xpath("html/body//input[@id='location']")).size();
    if (size > 0) {
        driver.findElement(By.xpath("html/body//input[@id='location']")).sendKeys("90007");
        driver.findElement(By.xpath("html/body//div[@class='mt10'][1]/a")).click();
        ;//w  w w . ja  va2s.c om
    }
    size = driver.findElements(By.xpath("html/body//div[@id='footer']/div[1]/a[3]")).size();

    if (size > 0 && processFirstIwana == true) {
        driver.findElement(By.xpath("html/body//div[@id='footer']/div[1]/a[3]")).click();
        processFirstIwana = false;
    }
    size = driver.findElements(By.xpath("html/body//div[@id='paging']//a[@class='next']")).size();
    if (size > 0) {
        driver.findElement(By.xpath("html/body//div[@id='paging']//a[@class='next']")).click();
    }
}

From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.Pagination.PaginationHandler18.java

License:Apache License

public void processBudgunshop(WebDriver driver) {
    int size = driver
            .findElements(By.xpath("html/body//form[@id='formcompare']/table[1]//a[@title=' Next Page ']"))
            .size();/*from w  ww.  j  a  va2  s . c  om*/
    if (size > 0) {
        driver.findElement(By.xpath("html/body//form[@id='formcompare']/table[1]//a[@title=' Next Page ']"))
                .click();
    }
}

From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.Pagination.PaginationHandler18.java

License:Apache License

public void processBuyusedguns(WebDriver driver) {
    ArrayList<WebElement> elemList = (ArrayList<WebElement>) driver
            .findElements(By.xpath("html/body//div[@class='pageNav'][1]//td[@class='paginationNum']/a"));
    if (elemList.size() > 0) {
        for (WebElement e : elemList) {
            String q = e.getText();
            if (q.equals(">")) {
                e.click();//from   w  w  w  .  j  a  v  a 2s . c  o  m
                break;
            }
        }
    }
}

From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.Pagination.PaginationHandler18.java

License:Apache License

public void processCheaperthandirt(WebDriver driver) {
    FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver);
    wait.until(new Predicate<WebDriver>() {
        public boolean apply(WebDriver driver) {
            return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete");
        }/*from w  w w.j  a  v a2 s .  c  o m*/
    });
    int size = driver
            .findElements(
                    By.id("ctl00_ctl00_ContentPlaceHolderTopLevel_ContentPlaceHolderItemList_displayTopDDL"))
            .size();
    if (size > 0) {
        Select dropdown = new Select(driver.findElement(
                By.id("ctl00_ctl00_ContentPlaceHolderTopLevel_ContentPlaceHolderItemList_displayTopDDL")));
        dropdown.selectByVisibleText("Show All");
    }

}

From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.Pagination.PaginationHandler18.java

License:Apache License

public void process4chan(WebDriver driver) {
    int size = driver.findElements(By.xpath("/html/body//form[@class='pageSwitcherForm']/input[@value='Next']"))
            .size();/*from w  w  w  .  java2s  .  co m*/
    if (size > 0) {
        WebElement next = driver
                .findElement(By.xpath("/html/body//form[@class='pageSwitcherForm']/input[@value='Next']"));
        next.click();
    }
}

From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.Pagination.PaginationHandler18.java

License:Apache License

public void processtenness(WebDriver driver) {

    int next24 = driver.findElements(By.xpath("/html/body//div[@id='cwv3_enter']/a")).size();
    if (next24 > 0) {
        WebElement next1 = driver.findElement(By.xpath("/html/body//div[@id='cwv3_enter']/a"));
        next1.click();/*w  w  w.  ja va 2  s. co  m*/
    }

    int next23 = driver.findElements(By.xpath("/html/body//div[@id='block1']/div[@class='paging']/a")).size();
    if (next23 > 0) {
        WebElement next2 = driver.findElement(By.xpath("/html/body//div[@id='block1']/div[@class='paging']/a"));
        next2.click();
    }

    String text1 = driver.findElement(By.xpath("/html/body//div[@class='pages']/span[@class='current']"))
            .getText();
    int str1 = Integer.parseInt(text1);
    int test1 = driver.findElements(By.xpath("/html/body//div[@class='pages']/a[" + str1 + "]")).size();
    if (test1 > 0) {
        WebElement next2w = driver.findElement(By.xpath("/html/body//div[@class='pages']/a[" + str1 + "]"));
        next2w.click();
    }

}

From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.Pagination.PaginationHandler18.java

License:Apache License

public void processzidaho(WebDriver driver) {
    int test1 = 8;
    int test2 = driver
            .findElements(By.xpath(/*from ww  w.j  a  v a2 s .co  m*/
                    "/html/body//ul[@class='pagination browsing_result_page_links']/li[" + test1 + "]/a"))
            .size();
    if (test2 > 0) {
        WebElement next2w = driver.findElement(
                By.xpath("/html/body//ul[@class='pagination browsing_result_page_links']/li[" + test1 + "]/a"));
        next2w.click();
    }
}