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.coderoad.automation.common.util.PageUtil.java

License:Open Source License

/**
 * Gets the element.//from   w ww.j  a  v a  2 s.  co m
 * 
 * @param driver the driver
 * @param attributeName the attribute name
 * @param attributeValue the attribute value
 * @param timeout the timeout
 * @return the element
 */
public static WebElement getElement(final WebDriver driver, final String attributeName,
        final String attributeValue, final Timeout timeout) {

    try {
        return new WebDriverWait(driver, timeout.getValue())
                .until(ExpectedConditions.presenceOfElementLocated(attribute(attributeName, attributeValue)));
    } catch (Exception ex) {
        return null;
    }
}

From source file:com.coderoad.automation.common.util.PageUtil.java

License:Open Source License

/**
 * Gets the elements./*from   w  w  w  . j a  va2 s.  c  o  m*/
 * 
 * @param driver the driver
 * @param locator the locator
 * @param timeout the timeout
 * @return the elements
 */
public static List<WebElement> getElements(final WebDriver driver, final By locator, final Timeout timeout) {

    try {
        return new WebDriverWait(driver, timeout.getValue())
                .until(ExpectedConditions.presenceOfAllElementsLocatedBy(locator));
    } catch (Exception ex) {
        return null;
    }
}

From source file:com.coderoad.automation.common.util.PageUtil.java

License:Open Source License

/**
 * Gets the element by sub element.//from  w w w  . j ava 2  s . c  om
 * 
 * @param driver the driver
 * @param element the element
 * @param locator the locator
 * @param timeout the timeout
 * @return the element by sub element
 */
public static WebElement getElementBySubElement(final WebDriver driver, final WebElement element,
        final By locator, Timeout timeout) {

    try {
        return new WebDriverWait(driver, timeout.getValue()).until(new ExpectedCondition<WebElement>() {

            public WebElement apply(final WebDriver driver) {

                if (element.findElement(locator) != null) {
                    return element.findElement(locator);
                }
                return null;
            }
        });
    } catch (Exception e) {
        return null;
    }
}

From source file:com.coderoad.automation.common.util.PageUtil.java

License:Open Source License

/**
 * Gets the elements by sub element./*  w  w w. j ava2 s . c om*/
 * 
 * @param driver the driver
 * @param element the element
 * @param locator the locator
 * @param timeout the timeout
 * @return the elements by sub element
 */
public static List<WebElement> getElementsBySubElement(final WebDriver driver, final WebElement element,
        final By locator, Timeout timeout) {

    try {
        return new WebDriverWait(driver, timeout.getValue()).until(new ExpectedCondition<List<WebElement>>() {

            public List<WebElement> apply(final WebDriver driver) {

                if (element.findElement(locator) != null) {
                    return element.findElements(locator);
                }
                return null;
            }
        });
    } catch (Exception e) {
        return null;
    }
}

From source file:com.coderoad.automation.common.util.PageUtil.java

License:Open Source License

/**
 * Checks if is page load complete./*  w w  w .  j av a 2  s  .  c o m*/
 * 
 * @param driver the driver
 * @return true, if is page load complete
 */
public static boolean isPageLoadComplete(final WebDriver driver) {

    try {
        return new WebDriverWait(driver, 120).until(new ExpectedCondition<Boolean>() {

            public Boolean apply(final WebDriver driver) {

                return ((JavascriptExecutor) driver).executeScript("return document.readyState")
                        .equals("complete");
            }
        });
    } catch (Exception ex) {
        return false;
    }
}

From source file:com.coderoad.automation.common.util.PageUtil.java

License:Open Source License

/**
 * Checks if is text displayed in source.
 * /*from  ww  w .j a  v  a 2 s  . co  m*/
 * @param driver the driver
 * @param content the content
 * @param timeout the timeout
 * @return true, if is text displayed in source
 */
public static boolean isTextDisplayedInSource(final WebDriver driver, final String content, Timeout timeout) {

    try {
        return new WebDriverWait(driver, timeout.getValue()).until(new ExpectedCondition<Boolean>() {

            public Boolean apply(final WebDriver driver) {

                return driver.getPageSource().contains(content);
            }
        });
    } catch (Exception ex) {
        return false;
    }
}

From source file:com.coderoad.automation.rocketTruedx.RocketTruedxNaBasePage.java

License:Open Source License

protected WebElement waitForElement(final By by) {

    WebElement element = null;//from   w  ww. j a v a  2 s  .co m
    TestLogger.logMsg("Start waitForElement : + " + this.getTimeStamp());
    for (int i = 0; i < 1; i++) {
        try {
            element = new WebDriverWait(driver, TestUtils.timeout).until(new ExpectedCondition<WebElement>() {

                @Override
                public WebElement apply(WebDriver d) {

                    return d.findElement(by);
                }
            });
        } catch (Exception e) {
            TestLogger.logMsg("Wait waitForElement : + " + this.getTimeStamp());
        }
    }
    TestLogger.logMsg("Done waitForElement : + " + this.getTimeStamp());
    return element;
}

From source file:com.coderoad.automation.rocketTruedx.RocketTruedxNaBasePage.java

License:Open Source License

protected void waitForVisibility(WebElement element) {

    TestLogger.logMsg("Start waitForVisibility : + " + this.getTimeStamp());
    for (int i = 0; i < 2; i++) {
        try {/*from  w  ww  .j a va  2 s . c o m*/
            WebElement myDynamicElement = (new WebDriverWait(driver, TestUtils.timeout))
                    .until(ExpectedConditions.visibilityOf(element));
        } catch (Exception e) {
            TestLogger.logMsg("Wait waitForVisibility : + " + this.getTimeStamp());
        }
    }
    TestLogger.logMsg("Done waitForVisibility : + " + this.getTimeStamp());
}

From source file:com.coderoad.automation.rocketTruedx.RocketTruedxNaBasePage.java

License:Open Source License

protected void waitForElementPresence(String element) {

    TestLogger.logMsg("Start waitForElementPresence : + " + this.getTimeStamp());
    for (int i = 0; i < 1; i++) {
        try {//from   ww w.j a  v a2s. c  om
            WebElement myDynamicElement = (new WebDriverWait(driver, TestUtils.timeout))
                    .until(ExpectedConditions.elementToBeClickable(By.id(element)));
        } catch (Exception e) {
            TestLogger.logMsg("Wait waitForElementPresence : + " + this.getTimeStamp());
        }
    }
    TestLogger.logMsg("Done waitForElementPresence : + " + this.getTimeStamp());
}

From source file:com.coderoad.automation.rocketTruedx.RocketTruedxNaBasePage.java

License:Open Source License

protected void waitForElementPresence(final By by) {

    TestLogger.logMsg("Start waitForElementPresence : + " + this.getTimeStamp());
    for (int i = 0; i < 1; i++) {
        try {//from  w w w . j  a  va  2  s  .  c  o m
            WebElement myDynamicElement = (new WebDriverWait(driver, TestUtils.timeout))
                    .until(ExpectedConditions.elementToBeClickable(by));
        } catch (Exception e) {
            TestLogger.logMsg("Wait waitForElementPresence : + " + this.getTimeStamp());
        }

    }
    TestLogger.logMsg("Done waitForElementPresence : + " + this.getTimeStamp());
}