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:org.auraframework.test.perf.custom.IterationComponentTest.java

License:Apache License

public void TODO_testChangePageSize() throws Throwable {
    // Shrink the list to 20 items.
    WebElement inputText = currentDriver.findElement(By.cssSelector(".pageSize"));
    inputText.sendKeys("20");
    WebElement button = currentDriver.findElement(By.cssSelector(".changePageSize"));
    button.click();// w  w  w .j  a v a  2  s  . co  m

    waitUntil(new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver d) {
            return d.findElements(By.cssSelector(".container div")).size() < 25;
        }
    });
}

From source file:org.auraframework.test.perf.custom.IterationComponentTest.java

License:Apache License

public void TODO_testChangePageCount() throws Throwable {
    final int pageSize = 25;
    final int pageCount = 20;
    WebElement inputText = currentDriver.findElement(By.cssSelector(".pageCount"));
    inputText.clear();/*from w w w. jav  a2s. c o m*/
    inputText.sendKeys(Integer.toString(pageCount));
    WebElement button = currentDriver.findElement(By.cssSelector(".changePageCount"));
    button.click();

    waitUntil(new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver d) {
            return d.findElements(By.cssSelector(".container div")).size() > pageCount * pageSize;
        }
    });
}

From source file:org.auraframework.test.perf.custom.RenderIfComponentTest.java

License:Apache License

public void TODO_testChangeCount() throws Throwable {
    // Change number of first level renderIf's to 200.
    final int numberOfRows = 200;
    WebElement inputText = currentDriver.findElement(By.cssSelector(".count"));
    inputText.clear();// w ww .j  a va  2  s .c  om
    inputText.sendKeys(Integer.toString(numberOfRows));
    WebElement button = currentDriver.findElement(By.cssSelector(".changeCount"));
    button.click();

    waitUntil(new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver d) {
            return d.findElements(By.cssSelector(".container div")).size() > numberOfRows;
        }
    });
}

From source file:org.auraframework.test.util.AuraUITestingUtil.java

License:Apache License

/**
 * Waits for element to be not present/*  www.  jav  a  2 s  . com*/
 * 
 * @param locator By of element waiting to disapear
 * @return
 */
public boolean waitForElementNotPresent(String msg, final By locator) {
    WebDriverWait wait = new WebDriverWait(driver, timeoutInSecs);
    return wait.withMessage(msg).ignoring(StaleElementReferenceException.class)
            .until(new ExpectedCondition<Boolean>() {
                @Override
                public Boolean apply(WebDriver d) {
                    return d.findElements(locator).isEmpty();
                }
            });
}

From source file:org.bigtester.ate.model.page.elementfind.AbstractElementFind.java

License:Apache License

/**
 * Find through frames.//from ww  w. j a  v a 2 s . c  o m
 *
 * @param win
 *            the win
 * @param winFrame
 *            the win frame
 * @param wait
 *            the wait
 * @param findByValue
 *            the find by value
 * @return the web element
 */
@Nullable
protected WebElement findThroughFrames(BrowserWindow win, WindowFrame winFrame, Wait<WebDriver> wait,
        final By findByValue) {
    win.getCurrentElementFindFrameChain().add(winFrame);
    winFrame.obtainFrameFocus();
    WebElement retValWE = null;// NOPMD
    try {
        retValWE = wait.until( // NOPMD
                new Function<WebDriver, WebElement>() {
                    public @Nullable WebElement apply( // NOPMD
                            @Nullable WebDriver driver) {
                        if (null == driver) {
                            throw new IllegalStateException("webdriver is not correctly populated.");
                        } else {
                            List<WebElement> allElements = driver.findElements(findByValue);
                            if (allElements.size() == 0)
                                throw new NoSuchElementException(findByValue.toString());
                            WebElement retVal;
                            int intIndex = getIndexOfSameElementsInt();
                            if (intIndex < -1) {
                                retVal = allElements.get(0);
                            } else if (intIndex == -1) {
                                retVal = allElements.get(allElements.size() - 1);
                            } else {
                                retVal = allElements.get(intIndex);
                            }
                            return retVal;
                            // return driver.findElement(findByValue);
                        }
                    }
                });
        if (null != retValWE) {
            if (!win.getLastSuccessElementFindFrameChain().equals(win.getCurrentElementFindFrameChain())) {
                win.getLastSuccessElementFindFrameChain().clear();
                win.getLastSuccessElementFindFrameChain().addAll(win.getCurrentElementFindFrameChain());
            }

        }
    } catch (NoSuchElementException | TimeoutException error) {
        List<WindowFrame> childFrames = winFrame.getChildFrames();
        for (WindowFrame gChildF : childFrames) {
            if (null == gChildF)
                throw GlobalUtils.createInternalError("java arraylist", error);
            retValWE = findThroughFrames(win, gChildF, wait, findByValue);
            if (null != retValWE) {

                break;
            }
        }
    }
    if (null == retValWE) {
        if (winFrame.getParentFrame() == null) {
            winFrame.focusDefautContent();
        } else {
            winFrame.focusParentFrame();
        }
    }

    return retValWE;
}

From source file:org.bigtester.ate.model.page.elementfind.AbstractElementFind.java

License:Apache License

/**
 * Find element./*ww w  .ja  va2s .co m*/
 *
 * @param findBy
 *            the find by
 * @param myWebDriver
 *            the my web driver
 * @return the web element
 */
protected WebElement findElement(final By findBy, IMyWebDriver myWebDriver) {
    WebDriver webD = myWebDriver.getWebDriver();
    if (null == webD) {
        throw new IllegalStateException("web driver is not correctly populated.");
    } else {
        createWait(webD);

        BrowserWindow winOnFocus = myWebDriver.getMultiWindowsHandler().getBrowserWindowOnFocus();
        winOnFocus.switchToDefaultContent();
        if (!winOnFocus.getLastSuccessElementFindFrameChain().isEmpty()) {
            for (WindowFrame lastSuccessWFrame : winOnFocus.getLastSuccessElementFindFrameChain()) {
                lastSuccessWFrame.obtainFrameFocus();
            }
        }
        WebElement retValWE = null;// NOPMD
        try {
            retValWE = getWait().until( // NOPMD
                    new Function<WebDriver, WebElement>() {
                        public @Nullable WebElement apply( // NOPMD
                                @Nullable WebDriver driver) {
                            if (null == driver) {
                                throw new IllegalStateException("webdriver is not correctly populated.");
                            } else {
                                List<WebElement> allElements = driver.findElements(findBy);
                                if (allElements.size() == 0)
                                    throw new NoSuchElementException(findByValue);
                                WebElement retVal;
                                int intIndex = getIndexOfSameElementsInt();
                                if (intIndex < -1) {
                                    retVal = allElements.get(0);
                                } else if (intIndex == -1) {
                                    retVal = allElements.get(allElements.size() - 1);
                                } else {
                                    retVal = allElements.get(intIndex);
                                }
                                return retVal;
                            }
                        }
                    });

        } catch (NoSuchElementException | TimeoutException error) {
            winOnFocus.getCurrentElementFindFrameChain().clear();
            for (WindowFrame winfr : winOnFocus.getVisibleFrames()) {

                try {
                    if (null == winfr)
                        throw GlobalUtils.createInternalError("arraylist error", error);
                    winfr.focusDefautContent();
                    retValWE = findThroughFrames(winOnFocus, winfr, getWait(), findBy);

                    if (null == retValWE)
                        winfr.focusDefautContent();
                    else {
                        break;
                    }
                } catch (NoSuchElementException | TimeoutException error1) {

                    continue;
                }

            }
        }
        if (null != retValWE) {
            return retValWE;
        }
        throw new NoSuchElementException(findBy.toString());
    }
}

From source file:org.callimachusproject.webdriver.helpers.WebBrowserDriver.java

License:Apache License

public void waitForFrameToClose(final String frameName) {
    driver.switchTo().window(driver.getWindowHandle());
    if (frameName != null) {
        try {/*from ww  w.  j  a va  2 s .  c o  m*/
            driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
            new WebDriverWait(driver, 60).until(new ExpectedCondition<Boolean>() {
                public Boolean apply(WebDriver driver) {
                    return driver.findElements(By.name(frameName)).isEmpty();
                }

                public String toString() {
                    return "frame " + frameName + " to be absent";
                }
            });
        } finally {
            driver.manage().timeouts().implicitlyWait(IMPLICITLY_WAIT, TimeUnit.SECONDS);
        }
    }
    waitForScript();
}

From source file:org.callimachusproject.webdriver.helpers.WebBrowserDriver.java

License:Apache License

public void waitUntilTextPresent(final By locator, final String needle) {
    waitForScript();/*from   ww  w .  j  a va  2s.  c o m*/
    try {
        driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
        Wait<WebDriver> wait = new WebDriverWait(driver, 60);
        Boolean present = wait.until(new ExpectedCondition<Boolean>() {
            public Boolean apply(WebDriver driver) {
                for (WebElement element : driver.findElements(locator)) {
                    try {
                        if (element.getText().contains(needle)) {
                            return true;
                        }
                    } catch (StaleElementReferenceException e) {
                        continue;
                    }
                }
                return null;
            }

            public String toString() {
                return "text " + needle + " to be present in " + locator;
            }
        });
        assertTrue(present);
    } finally {
        driver.manage().timeouts().implicitlyWait(IMPLICITLY_WAIT, TimeUnit.SECONDS);
    }
}

From source file:org.callimachusproject.webdriver.helpers.WebBrowserDriver.java

License:Apache License

public void waitUntilModalOpen() {
    Wait<WebDriver> wait = new WebDriverWait(driver, 240);
    assertTrue(wait.until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver wd) {
            List<WebElement> modals = wd.findElements(By.cssSelector(".modal.fade.in"));
            if (modals.isEmpty())
                return false;
            for (WebElement modal : modals) {
                if (!modal.getCssValue("opacity").equals("1"))
                    return false;
            }//from w ww. jav a  2s.  c  o m
            return true;
        }

        public String toString() {
            return "modal to open";
        }
    }));
}

From source file:org.codelibs.fess.crawler.client.http.action.AOnClickAction.java

License:Apache License

@Override
public void navigate(final WebDriver webDriver, final Map<String, String> paramMap) {
    final String cssQuery = paramMap.get(CSS_QUERY);
    final int index = Integer.parseInt(paramMap.get(INDEX));
    if (StringUtil.isNotBlank(cssQuery) && index >= 0) {
        final List<WebElement> elementList = webDriver.findElements(By.cssSelector(cssQuery));
        if (index < elementList.size()) {
            elementList.get(index).click();
            return;
        }//from  w w  w . j a va  2s.  co  m
    }
    throw new CrawlerSystemException("Invalid position. css query: " + cssQuery + ", index: " + index);
}