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.old.BasePage.java

License:Open Source License

/**
 * Wait for page loaded./*  w ww.j a  v a 2  s  .c  o m*/
 */
public void waitForPageLoaded() {

    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(this.getDriver(), TestUtils.timeout);
    try {
        wait.until(expectation);
    } catch (Throwable error) {
        LogUtil.log("Timeout waiting for Page Load Request to complete.", LogLevel.HIGH);
    }
}

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

License:Open Source License

/**
 * Checks if is displayed./* ww  w.ja  v a 2  s  .c o m*/
 * 
 * @param driver the driver
 * @param locator the locator
 * @param timeout the timeout
 * @return true, if is displayed
 */
public static boolean isDisplayed(final WebDriver driver, final By locator, final Timeout timeout) {

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

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

License:Open Source License

/**
 * Checks if is visible./* w  w  w . j  a v a2s.co m*/
 * 
 * @param driver the driver
 * @param locator the locator
 * @param timeout the timeout
 * @return true, if is visible
 */
public static boolean isVisible(final WebDriver driver, final By locator, final Timeout timeout) {
    LogUtil.log("Check the Element is Visible(By Locator) ", LogLevel.HIGH);

    try {
        return new WebDriverWait(driver, timeout.getValue())
                .until(ExpectedConditions.visibilityOf(driver.findElement(locator))).isDisplayed();
    } catch (Exception ex) {
        return false;
    }
}

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

License:Open Source License

/**
 * Checks if is visible.//from w  w w  .j av  a2s  .  c o m
 * 
 * @param driver the driver
 * @param element the element
 * @param timeout the timeout
 * @return true, if is visible
 */
public static boolean isVisible(final WebDriver driver, final WebElement element, final Timeout timeout) {

    LogUtil.log("Check the Element is Visible(WebElement) ", LogLevel.HIGH);
    try {
        return new WebDriverWait(driver, timeout.getValue()).until(ExpectedConditions.visibilityOf(element))
                .isDisplayed();
    } catch (Exception ex) {
        return false;
    }
}

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

License:Open Source License

/**
 * Checks if is not displayed./*  ww  w .  j av a 2s . c  om*/
 * 
 * @param driver the driver
 * @param locator the locator
 * @param timeout the timeout
 * @return true, if is not displayed
 */
public static boolean isNotDisplayed(final WebDriver driver, final By locator, final Timeout timeout) {

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

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

License:Open Source License

/**
 * Checks if is enabled.//from w w  w  .  j a v a  2  s.c  o  m
 * 
 * @param driver the driver
 * @param locator the locator
 * @param timeout the timeout
 * @return true, if is enabled
 */
public static boolean isEnabled(final WebDriver driver, final By locator, final Timeout timeout) {

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

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

License:Open Source License

/**
 * Checks if is selected.//from ww  w  .  j  a  v a 2 s.  com
 * 
 * @param driver the driver
 * @param locator the locator
 * @param timeout the timeout
 * @return true, if is selected
 */
public static boolean isSelected(final WebDriver driver, final By locator, final Timeout timeout) {

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

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

License:Open Source License

/**
 * Checks if is element clickable.//from  w  ww  . java 2 s  . c o  m
 * 
 * @param driver the driver
 * @param element the element
 * @param timeout the timeout
 * @return the web element
 */
public static WebElement isElementClickable(final WebDriver driver, final WebElement element,
        final Timeout timeout) {

    try {
        return new WebDriverWait(driver, timeout.getValue())
                .until(ExpectedConditions.elementToBeClickable(element));
    } catch (Exception te) {
        return null;
    }
}

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

License:Open Source License

public static boolean isWebElementClickable(final WebDriver driver, final WebElement element,
        final Timeout timeout) {

    try {/*  w w  w. j a v  a 2 s.  c om*/
        return new WebDriverWait(driver, timeout.getValue())
                .until(ExpectedConditions.elementToBeClickable(element)).isDisplayed();
    } catch (Exception te) {
        return false;
    }
}

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

License:Open Source License

/**
 * Gets the element.//from  ww  w . j  av  a2 s.c  om
 * 
 * @param driver the driver
 * @param locator the locator
 * @param timeout the timeout
 * @return the element
 */
public static WebElement getElement(final WebDriver driver, final By locator, final Timeout timeout) {

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