Example usage for org.openqa.selenium.support.ui ExpectedConditions visibilityOfAllElements

List of usage examples for org.openqa.selenium.support.ui ExpectedConditions visibilityOfAllElements

Introduction

In this page you can find the example usage for org.openqa.selenium.support.ui ExpectedConditions visibilityOfAllElements.

Prototype

public static ExpectedCondition<List<WebElement>> visibilityOfAllElements(final List<WebElement> elements) 

Source Link

Document

An expectation for checking that all elements present on the web page that match the locator are visible.

Usage

From source file:com.codenvy.corp.MainPage.java

License:Open Source License

public void gotoMainPageWaitAuthorizePageAndLogin(String login, String passWord) throws InterruptedException {
    driver.get(baseUrl);/*from   ww  w  . j  a v  a  2 s  . c o  m*/
    new WebDriverWait(driver, 40)
            .until(ExpectedConditions.visibilityOfAllElements(Arrays.asList(loginField, passField)));
    loginField.sendKeys(login);
    passField.sendKeys(passWord);
    loginBtnb.click();
    Thread.sleep(15000);
    new WebDriverWait(driver, 5).until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Agile")))
            .click();
    initId();

}

From source file:com.ggasoftware.uitest.control.Elements.java

License:Open Source License

/**
 * Wait until all elements is invisible/*from   ww w . j a  va2 s .com*/
 *
 * @param timeoutSec     seconds to wait until all elements become Not Visible
 * @param checkCondition log assert for expected conditions.
 * @return Parent instance
 */
public ParentPanel waitForAllElementsNotVisible(final int timeoutSec, final boolean checkCondition) {
    logAction(this, getParentClassName(), format("waitForAllElementsNotVisible: %s", locator));
    boolean isNotVisible;
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    setTimeout(1);
    try {
        wait.until(ExpectedConditions.not(ExpectedConditions.visibilityOfAllElements(getWebElements())));
        isNotVisible = true;
    } catch (TimeoutException e) {
        logTechnical(format("waitForAllElementsNotVisible: [ %s ] during: [ %d ] sec ", locator,
                System.currentTimeMillis() / 1000 - start));
        isNotVisible = false;
    } catch (NoSuchElementException elementException) {
        isNotVisible = false;
    }
    setTimeout(TIMEOUT);
    if (checkCondition) {
        ReporterNGExt.logAssertTrue(ReporterNGExt.BUSINESS_LEVEL, isNotVisible,
                format("waitForAllElementsNotVisible - all element of '%s' should be not visible", name),
                TestBaseWebDriver.takePassedScreenshot);
    }
    return parent;
}

From source file:com.ggasoftware.uitest.control.Elements.java

License:Open Source License

/**
 * Wait until all elements is visible//from ww w .  j  av a2  s.  c  o  m
 *
 * @param timeoutSec     seconds to wait until all elements become Visible
 * @param checkCondition log assert for expected conditions.
 * @return Parent instance
 */
public ParentPanel waitForAllElementsVisible(final int timeoutSec, final boolean checkCondition) {
    logAction(this, getParentClassName(), format("waitForAllElementsVisible: %s", locator));
    boolean isVisible;
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    setTimeout(1);
    try {
        wait.until(ExpectedConditions.visibilityOfAllElements(getWebElements()));
        isVisible = true;
    } catch (TimeoutException e) {
        logTechnical(format("waitForAllElementsVisible: [ %s ] during: [ %d ] sec ", locator,
                System.currentTimeMillis() / 1000 - start));
        isVisible = false;
    }
    setTimeout(TIMEOUT);
    if (checkCondition) {
        ReporterNGExt.logAssertTrue(ReporterNGExt.BUSINESS_LEVEL, isVisible,
                format("waitForAllElementsVisible - all elements of '%s' should be visible", name),
                TestBaseWebDriver.takePassedScreenshot);
    }
    return parent;
}

From source file:com.github.codewrs.selenium.FindElementAdvanced.java

License:Open Source License

/**
 * Find all elements within the WebElement using the given mechanism.
 * Returns WebElement by matching with index of the WebElement.
 * @param driver WebDriver instance./* ww w.  j a v  a  2  s  .  c  o  m*/
 * @param by The locating mechanism.
 * @param elementIndex Index of the WebElement to find.
 * @param wait Explicit Wait Time.
 * @return WebElement or null if nothing matches.
 */
protected WebElement findElementOnList(WebDriver driver, By by, int elementIndex, WebDriverWait wait) {
    try {
        List<WebElement> elementList = driver.findElements(by);
        wait.until(ExpectedConditions.visibilityOfAllElements(elementList));
        int listSize = elementList.size();
        System.out.println("The number of element counted is : " + listSize);
        if (listSize > 0) {
            int i = 0;
            for (WebElement ele : elementList) {
                if (elementIndex == i) {
                    System.out.println("The returned WebElement text : " + ele.getText());
                    return ele;
                }
                i++;
            }
        }
    } catch (NoSuchElementException e) {
        System.out.println("No Element found.");
    }
    System.out.println("No Element found.");
    return null;
}

From source file:com.github.codewrs.selenium.FindElementAdvanced.java

License:Open Source License

/**
 * Find all elements within the WebElement using the given mechanism.
 * Returns WebElement by matching with index of the WebElement.
 * @param webElement Base WebElement containing the WebElements.
 * @param by The locating mechanism./* ww w  .  j  av  a2s . com*/
 * @param elementIndex Index of the WebElement to find.
 * @param wait Explicit Wait Time.
 * @return WebElement or null if nothing matches.
 */
protected WebElement findElementOnList(WebElement webElement, By by, int elementIndex, WebDriverWait wait) {
    try {
        List<WebElement> elementList = webElement.findElements(by);
        wait.until(ExpectedConditions.visibilityOfAllElements(elementList));
        int listSize = elementList.size();
        System.out.println("The number of element counted is : " + listSize);
        if (listSize > 0) {
            int i = 0;
            for (WebElement ele : elementList) {
                if (elementIndex == i) {
                    System.out.println("The returned WebElement text : " + ele.getText());
                    return ele;
                }
                i++;
            }
        }
    } catch (NoSuchElementException e) {
        System.out.println("No Element found.");
    }
    System.out.println("No Element found.");
    return null;
}

From source file:com.github.codewrs.selenium.FindElementAdvanced.java

License:Open Source License

/**
 * Find all elements within the current page using the given mechanism.
 * Returns WebElement with the matching text.
 * @param driver WebDriver instance.//w w w .j a v  a 2s. c  om
 * @param by The locating mechanism.
 * @param textToMatch Text to match with text of found WebElements.
 * @param wait Explicit Wait Time.
 * @return WebElement or null if nothing matches.
 */
protected WebElement findElementOnList(WebDriver driver, By by, String valueToMatch, WebDriverWait wait) {
    try {
        List<WebElement> elementList = driver.findElements(by);
        wait.until(ExpectedConditions.visibilityOfAllElements(elementList));
        int listSize = elementList.size();
        System.out.println("The number of element counted is : " + listSize);
        if (listSize > 0) {
            for (WebElement ele : elementList) {
                if (ele.getText() != null) {
                    if (ele.getText().contentEquals(valueToMatch)) {
                        System.out.println("The returned WebElement text : " + ele.getText());
                        return ele;
                    }
                }
            }
        }
    } catch (NoSuchElementException e) {
        System.out.println("No Element found.");
    }
    System.out.println("No Element found.");
    return null;
}

From source file:com.github.codewrs.selenium.FindElementAdvanced.java

License:Open Source License

/**
 * Find all the elements within the WebElement using the given mechanism.
 * Returns WebElement with the matching text.
 * @param webElement Base WebElement to find other WebElements.
 * @param by The locating mechanism.//from   w ww  .ja  va 2  s.c  o  m
 * @param textToMatch Text to match with text of found WebElements.
 * @param wait Explicit Wait Time.
 * @return WebElement or null if nothing matches.
 */
protected WebElement findElementOnList(WebElement webElement, By by, String valueToMatch, WebDriverWait wait) {
    try {
        List<WebElement> elementList = webElement.findElements(by);
        wait.until(ExpectedConditions.visibilityOfAllElements(elementList));
        int listSize = elementList.size();
        System.out.println("The number of element counted is : " + listSize);
        if (listSize > 0) {
            for (WebElement ele : elementList) {
                if (ele.getText() != null) {
                    if (ele.getText().contentEquals(valueToMatch)) {
                        System.out.println("The returned WebElement text : " + ele.getText());
                        return ele;
                    }
                }
            }
        }
    } catch (NoSuchElementException e) {
        System.out.println("No Element found.");
    }
    System.out.println("No Element found.");
    return null;
}

From source file:com.github.codewrs.selenium.FindElementAdvanced.java

License:Open Source License

/**
 * Find all elements within the current page using the given mechanism.
 * Returns WebElement by matching the value of the attribute.
 * @param driver WebDriver instance./* ww  w . java2s.  c  o  m*/
 * @param by The locating mechanism.
 * @param attributeToSearch The attribute to locate. 
 * @param valueToMatch Text to match with attribute's value.
 * @param wait Explicit Wait Time.
 * @return WebElement or null if nothing matches.
 */
protected WebElement findElementOnList(WebDriver driver, By by, String attributeToSearch, String valueToMatch,
        WebDriverWait wait) {
    try {
        List<WebElement> elementList = driver.findElements(by);
        wait.until(ExpectedConditions.visibilityOfAllElements(elementList));
        int listSize = elementList.size();
        System.out.println("The number of WebElements found : " + listSize);
        if (listSize > 0) {
            for (WebElement ele : elementList) {
                if (ele.getAttribute(attributeToSearch) != null) {
                    if (ele.getAttribute(attributeToSearch).contentEquals(valueToMatch)) {
                        System.out.println("The returned WebElement text : " + ele.getText());
                        return ele;
                    }
                }
            }
        }
    } catch (NoSuchElementException e) {
        System.out.println("No Element found.");
    }
    System.out.println("No Element found.");
    return null;
}

From source file:com.github.codewrs.selenium.FindElementAdvanced.java

License:Open Source License

/**
 * Find all the elements within the WebElement using the given mechanism.
 * Returns WebElement by matching with the value of the attribute.
 * @param webElement Base WebElement to find other WebElements.
 * @param by The locating mechanism.//from   ww  w.  j  av  a 2 s .c o m
 * @param attributeToSearch The attribute to locate. 
 * @param valueToMatch Text to match with attribute's value.
 * @param wait Explicit Wait Time.
 * @return WebElement or null if nothing matches.
 */
protected WebElement findElementOnList(WebElement webElement, By by, String attributeToSearch,
        String valueToMatch, WebDriverWait wait) {
    try {
        List<WebElement> elementList = webElement.findElements(by);
        wait.until(ExpectedConditions.visibilityOfAllElements(elementList));
        int listSize = elementList.size();
        System.out.println("The number of WebElements found : " + listSize);
        if (listSize > 0) {
            for (WebElement ele : elementList) {
                if (ele.getAttribute(attributeToSearch) != null) {
                    if (ele.getAttribute(attributeToSearch).contentEquals(valueToMatch)) {
                        System.out.println("The returned WebElement text : " + ele.getText());
                        return ele;
                    }
                }
            }
        }
    } catch (NoSuchElementException e) {
        System.out.println("No Element found.");
    }
    System.out.println("No Element found.");
    return null;
}

From source file:com.github.codewrs.selenium.FindElementAdvanced.java

License:Open Source License

/**
 * Find all <tr> tags within the current table body.
 * Then searches <th> tags for each <tr>. 
 * Returns <tr> WebElement by matching with <th> text.
 * @param tBody WebElement of the table body.
 * @param thTextToMatch Text to match with <th> tag's text.
 * @param wait Explicit Wait Time.//  w  ww.j  a v  a  2 s.c o  m
 * @return WebElement or null if nothing matches.
 */
protected WebElement findElementOnTable(WebElement tBody, String thTextToMatch, WebDriverWait wait) {
    try {
        List<WebElement> trList = tBody.findElements(By.tagName("tr"));
        wait.until(ExpectedConditions.visibilityOfAllElements(trList));
        int trSize = trList.size();
        if (trSize > 0) {
            for (WebElement webElement : trList) {
                List<WebElement> tdList = webElement.findElements(By.tagName("td"));
                int thSize = tdList.size();
                if (thSize > 0) {
                    for (WebElement ele : tdList) {
                        if (ele.getText() != null) {
                            if (ele.getText().equals(thTextToMatch)) {
                                System.out.println("The returned WebElement text : " + ele.getText());
                                return ele;
                            }
                        }
                    }
                }
            }
        }
    } catch (NoSuchElementException e) {
        System.out.println("No Element found.");
    }
    System.out.println("No Element found.");
    return null;
}