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.rocketTruedx.RocketTruedxNaBasePage.java

License:Open Source License

public void waitForPageLoaded() {

    ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>() {

        public Boolean apply(WebDriver driver) {

            return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete");
        }/*from   w  w w . j  a v a2s  .co  m*/
    };

    Wait<WebDriver> wait = new WebDriverWait(this.getDriver(), TestUtils.timeout);
    try {
        wait.until(expectation);
    } catch (Throwable error) {
        TestLogger.logError("Timeout waiting for Page Load Request to complete.");
    }
}

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

License:Open Source License

/**
 * Wait for element.// w  w w. jav a2  s .c om
 * 
 * @param by the by
 * @return the web element
 */
protected WebElement waitForElement(final By by) {

    WebElement element = null;
    TestLogger.logMsg("Start waitForElement : + " + TestUtils.getTimeStamp());
    for (int i = 0; i < 3; i++) {
        element = new WebDriverWait(driver, TestUtils.timeout).until(new ExpectedCondition<WebElement>() {
            @Override
            public WebElement apply(WebDriver d) {

                return d.findElement(by);
            }
        });
        TestLogger.logMsg("Wait waitForElement : + " + TestUtils.getTimeStamp());
    }
    TestLogger.logMsg("Done waitForElement : + " + TestUtils.getTimeStamp());
    return element;
}

From source file:com.cognifide.aet.job.common.modifiers.login.LoginFormComponent.java

License:Apache License

private WebElement getElementByXpath(WebDriver webDriver, String xpathExpression) {
    WebDriverWait wait = new WebDriverWait(webDriver, TIMEOUT);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpathExpression)));
    return webDriver.findElement(By.xpath(xpathExpression));
}

From source file:com.cognifide.aet.job.common.SeleniumWaitHelper.java

License:Apache License

public static void waitForElementToBePresent(WebDriver webDriver, By elementLocator, long timeOut)
        throws WebDriverException {
    WebDriverWait wait = new WebDriverWait(webDriver, timeOut);
    wait.until(ExpectedConditions.presenceOfElementLocated(elementLocator));
}

From source file:com.cognifide.aet.job.common.SeleniumWaitHelper.java

License:Apache License

public static void waitForElementToBeClickable(WebDriver webDriver, By elementLocator, long timeOut) {
    WebDriverWait wait = new WebDriverWait(webDriver, timeOut);
    wait.until(ExpectedConditions.elementToBeClickable(elementLocator));
}

From source file:com.cognifide.qa.bb.provider.selenium.BobcatWebDriverWait.java

License:Apache License

/**
 * This method enhances Selenium's "until" method.
 * First it reduces implicit timeout to a near-zero value.
 * Then a timer is started and the condition is checked cyclically until it is fulfilled
 * or the timer times out. Finally, implicit timeout is set back to the value
 * defined in the property file (under "webdriver.defaultTimeout").
 *
 * @param condition Selenium's condition object that is queried cyclically inside the wait loop.
 * @param <T>       The function's expected return type.
 * @return The functions' return value if the function returned something different.
 * from null or false before the timeout expired.
 *//* w  w w  .j  a  v a2  s  .c  om*/
public <T> T until(ExpectedCondition<T> condition) {
    webDriver.manage().timeouts().implicitlyWait(IMPLICITLY_WAIT_TIME, TimeUnit.SECONDS);
    final T result = new WebDriverWait(webDriver, timeOutInSeconds).until(condition::apply);
    webDriver.manage().timeouts().implicitlyWait(defaultTimeout, TimeUnit.SECONDS);
    return result;
}

From source file:com.comcast.dawg.house.AdvanceFilterUIIT.java

License:Apache License

private void performSearchAndCheckDevices(RemoteWebDriver driver, String[] deviceIdsToHave,
        String[] deviceIdsNotToHave) {
    WebElement filteredTable = driver.findElementByClassName(IndexPage.FILTERED_TABLE);

    WebDriverWait wait = new WebDriverWait(driver, 20);
    driver.findElementByClassName(IndexPage.BTN_SEARCH).click();

    /** Need two waits... first for the original table to be removed from the DOM, then for it
     * to be present again *//*from ww  w . ja  v a 2  s  .c  o m*/
    wait.until(ExpectedConditions.stalenessOf(filteredTable));
    wait.until(ExpectedConditions.presenceOfElementLocated(By.className(IndexPage.FILTERED_TABLE)));
    filteredTable = driver.findElementByClassName(IndexPage.FILTERED_TABLE);

    if (deviceIdsToHave != null) {
        hasDevices(filteredTable, deviceIdsToHave, true);
    }
    if (deviceIdsNotToHave != null) {
        hasDevices(filteredTable, deviceIdsNotToHave, false);
    }
}

From source file:com.comcast.dawg.house.ContextMenu.java

License:Apache License

/**
 * Clicks the Edit menu item and then waits for the Edit Overlay to be visible
 * @return/*from   w w w  . j a  v a  2s .c o m*/
 */
public EditDeviceOverlay launchEditDeviceOverlay() {
    clickMenuItem(ContextMenuItem.edit);
    WebDriverWait wait = new WebDriverWait(driver, 20);
    WebElement overlay = driver.findElement(By.className(EDIT_DEVICE_OVERLAY));
    wait.until(ExpectedConditions.visibilityOf(overlay));
    return new EditDeviceOverlay(driver, overlay);
}

From source file:com.comcast.dawg.house.EditDeviceUIIT.java

License:Apache License

private void waitForNewPageToLoad(RemoteWebDriver driver, WebElement oldPageElement) {
    WebDriverWait wait = new WebDriverWait(driver, 20);
    wait.until(ExpectedConditions.stalenessOf(oldPageElement));
    wait.until(ExpectedConditions.presenceOfElementLocated(By.className(IndexPage.FILTERED_TABLE)));
}

From source file:com.comcast.dawg.house.pages.IndexPage.java

License:Apache License

/**
 * Types the tag name and clicks the bulk tag button.
 *
 * @param  tagName  the tag names//ww  w  .  j  a  v a2 s  .co  m
 */
public void enterTagNameAndClickSubmit(String tagName) {

    // Enter the tag name.
    typeOnBulkTagTextElement(tagName);

    /**
     * If already tag is present in the tag cloud the element modification need to be evaluated for correct wait
     * time.
     **/
    String tagCloudElementText = getTagCloudElementText();
    boolean isTagPresent = false;
    List<WebElement> listOfContainedTag = new ArrayList<WebElement>();

    for (String tag : tagName.split(" ")) {

        if (tagCloudElementText.contains(tag)) {
            isTagPresent = true;
            listOfContainedTag
                    .add(driver.findElementByXPath(TAG_ID_DIV_XPATH.replace(REPLACEABLE_ELEMENT, tag)));
        }
    }

    // Clicking on bulk tag add button.
    clickOnBulkTagAddButton();

    WebDriverWait wait = new WebDriverWait(driver, 20);

    // If tag is present waiting for it to get refreshed.
    if (isTagPresent) {

        for (WebElement element : listOfContainedTag) {
            wait.until(ExpectedConditions.stalenessOf(element));
        }
    }

    // Since multi tag addition is supported.
    for (String tag : tagName.split(" ")) {
        wait.until(ExpectedConditions
                .presenceOfElementLocated(By.xpath(TAG_ID_DIV_XPATH.replace(REPLACEABLE_ELEMENT, tag))));
    }
}