Example usage for org.openqa.selenium.support.ui WebDriverWait WebDriverWait

List of usage examples for org.openqa.selenium.support.ui WebDriverWait WebDriverWait

Introduction

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

Prototype

public WebDriverWait(WebDriver driver, Duration timeout) 

Source Link

Document

Wait will ignore instances of NotFoundException that are encountered (thrown) by default in the 'until' condition, and immediately propagate all others.

Usage

From source file:com.ecofactor.qa.automation.util.PageUtil.java

License:Open Source License

/**
 * Retrieve element by tag text./*from  w ww  .  j a  va 2  s.co m*/
 * @param driver the driver
 * @param tagName the tag name
 * @param textValue the text value
 * @param timeOut the time out
 * @return the web element
 */
public static WebElement retrieveElementByTagText(final WebDriver driver, final String tagName,
        final String textValue, final int timeOut) {

    elementTagText = null;
    (new WebDriverWait(driver, timeOut)).until(new ExpectedCondition<Boolean>() {

        public Boolean apply(WebDriver d) {

            boolean isLoaded = false;
            List<WebElement> elementList = driver.findElements(By.tagName(tagName));
            for (WebElement webElement : elementList) {
                String value = webElement.getText();
                if (value.trim().equalsIgnoreCase(textValue)) {
                    elementTagText = webElement;
                    isLoaded = true;
                    break;
                }
            }
            return isLoaded;
        }
    });

    /*
     * WebElement element = null; List<WebElement> elementList =
     * driver.findElements(By.tagName(tagName)); for (WebElement webElement : elementList) {
     * String value = webElement.getText(); if(value.trim().equalsIgnoreCase(textValue)) return
     * webElement; }
     */

    return elementTagText;
}

From source file:com.ecofactor.qa.automation.util.PageUtil.java

License:Open Source License

/**
 * Contains by tag text./*from   w ww .j a v  a  2 s .  c o m*/
 * @param driver the driver
 * @param tagName the tag name
 * @param textValue the text value
 * @param timeOut the time out
 * @return the web element
 */
public static WebElement containsByTagText(final WebDriver driver, final String tagName, final String textValue,
        final int timeOut) {

    elementTagText = null;
    (new WebDriverWait(driver, timeOut)).until(new ExpectedCondition<Boolean>() {

        public Boolean apply(WebDriver d) {

            boolean isLoaded = false;
            List<WebElement> elementList = driver.findElements(By.tagName(tagName));
            for (WebElement webElement : elementList) {
                String value = webElement.getText();
                if (value.trim().contains(textValue)) {
                    elementTagText = webElement;
                    isLoaded = true;
                    break;
                }
            }
            return isLoaded;
        }
    });

    /*
     * WebElement element = null; List<WebElement> elementList =
     * driver.findElements(By.tagName(tagName)); for (WebElement webElement : elementList) {
     * String value = webElement.getText(); if(value.trim().equalsIgnoreCase(textValue)) return
     * webElement; }
     */

    return elementTagText;
}

From source file:com.ecofactor.qa.automation.util.PageUtil.java

License:Open Source License

/**
 * Retrieve sub element by tag text./*from   w  ww . j a  v a 2s  . co  m*/
 * @param driver the driver
 * @param subElelement the sub elelement
 * @param tagName the tag name
 * @param textValue the text value
 * @param timeOut the time out
 * @return the web element
 */
public static WebElement retrieveSubElementByTagText(final WebDriver driver, final WebElement subElelement,
        final String tagName, final String textValue, final int timeOut) {

    elementTagText = null;
    (new WebDriverWait(driver, timeOut)).until(new ExpectedCondition<Boolean>() {

        public Boolean apply(WebDriver d) {

            boolean isLoaded = false;
            List<WebElement> elementList = subElelement.findElements(By.tagName(tagName));
            for (WebElement webElement : elementList) {
                String value = webElement.getText();
                if (value.trim().equalsIgnoreCase(textValue)) {
                    elementTagText = webElement;
                    isLoaded = true;
                    break;
                }
            }
            return isLoaded;
        }
    });

    /*
     * WebElement element = null; List<WebElement> elementList =
     * driver.findElements(By.tagName(tagName)); for (WebElement webElement : elementList) {
     * String value = webElement.getText(); if(value.trim().equalsIgnoreCase(textValue)) return
     * webElement; }
     */

    return elementTagText;
}

From source file:com.ecofactor.qa.automation.util.PageUtil.java

License:Open Source License

/**
 * Utility to check weather the particular field is displayed by css class name.
 * @param driver the driver//from ww  w . j  a va2s  .c o m
 * @param fieldname the fieldname
 * @param textValue the text value
 * @param textValue2 the text value2
 * @param timeOut the time out
 * @return boolean
 */
public static boolean isDisplayedByClassNameForWeeklySchedule(final WebDriver driver, final String fieldname,
        final String textValue, final String textValue2, final int timeOut) {

    boolean isLoaded = false;
    isLoaded = (new WebDriverWait(driver, timeOut)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {

            boolean outcome = false;
            WebDriverWait wait = new WebDriverWait(driver, timeOut);
            wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.className(fieldname)));

            WebElement element = d.findElement(By.className(fieldname));

            if (element.getText().contains(textValue) || element.getText().contains(textValue2)) {
                outcome = true;
            }
            return outcome;
        }
    });
    return isLoaded;
}

From source file:com.ecofactor.qa.automation.util.PageUtil.java

License:Open Source License

/**
 * Checks if is form element clickable by id.
 * @param driver the driver/*w ww  .  j  a  v  a2s .  c  o  m*/
 * @param fieldname the fieldname
 * @param timeOut the time out
 */
public static void isFormElementClickableById(final WebDriver driver, final String fieldname,
        final int timeOut) {

    WebDriverWait wait = new WebDriverWait(driver, timeOut);
    wait.until(ExpectedConditions.elementToBeClickable(By.id(fieldname)));

}

From source file:com.ecofactor.qa.automation.util.PageUtil.java

License:Open Source License

/**
 * Close alert.//from w w w.j a  v  a  2s .c  o m
 *
 * @param driver the driver
 */
public static void closeAlert(WebDriver driver) {

    try {
        WebDriverWait wait = new WebDriverWait(driver, SHORT_TIMEOUT);
        if (wait.until(ExpectedConditions.alertIsPresent()) != null) {
            driver.switchTo().alert().accept();
        }
    } catch (Exception e) {
        // ignore any exception
    }
}

From source file:com.ecofactor.qa.automation.util.PageUtil.java

License:Open Source License

/**
 * Wait for page loaded.//from  w ww.  j  a  va 2 s.  c o m
 * @param driver the driver
 */
public static void waitForPageLoaded(WebDriver driver) {

    ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver driver) {

            return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete");
        }
    };

    Wait<WebDriver> wait = new WebDriverWait(driver, 120);
    try {
        wait.until(expectation);
    } catch (Throwable error) {
        DriverConfig.setLogString("Page load takes more time", true);
    }
}

From source file:com.econcept.selenium.method.Logout.java

License:Open Source License

@Override
public void activate() throws Exception {
    // If not even valid, return
    if (!isValid()) {
        return;/* ww w. ja v a 2 s .  com*/
    } // if

    try {
        String lXpathAction = "(//div[ ./a[starts-with(@class, 'gb_r gb_P gb_j identityWidgetIcon')]])[last()]";
        // Wait until element is visbile for 120 seconds
        WebDriverWait lWait = new WebDriverWait(mDriver, mTimeOut);
        Thread.sleep(WebDriverWait.DEFAULT_SLEEP_TIMEOUT);
        WebElement lElement = lWait
                .until(ExpectedConditions.visibilityOfElementLocated(By.xpath(lXpathAction)));
        lElement.click();

        lXpathAction = "(//div[ ./a[starts-with(@href, '?logout&')]])[last()]";

        Thread.sleep(WebDriverWait.DEFAULT_SLEEP_TIMEOUT);
        lElement = lWait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(lXpathAction)));
        lElement.click();
    } // try
    catch (Exception pException) {
        pException.printStackTrace();
        throw new Exception(pException);
    } // catch
}

From source file:com.elastica.webelements.BasePage.java

License:Apache License

public void waitForElementChecked(final HtmlElement element) {
    Assert.assertNotNull(element, "Element can't be null");
    TestLogging.logWebStep(null, "wait for " + element.toString() + " to be checked.", false);

    WebDriverWait wait = new WebDriverWait(driver, explictWaitTimeout);
    wait.until(ExpectedConditions.elementToBeSelected(element.getBy()));
}

From source file:com.elastica.webelements.BasePage.java

License:Apache License

public void waitForElementEditable(final HtmlElement element) {
    Assert.assertNotNull(element, "Element can't be null");
    TestLogging.logWebStep(null, "wait for " + element.toString() + " to be editable.", false);

    WebDriverWait wait = new WebDriverWait(driver, explictWaitTimeout);
    wait.until(ExpectedConditions.elementToBeClickable(element.getBy()));
}