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

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

Introduction

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

Prototype

public static ExpectedCondition<WebElement> presenceOfElementLocated(final By locator) 

Source Link

Document

An expectation for checking that an element is present on the DOM of a page.

Usage

From source file:NewCarTest.java

public void shouldWaitForPageToLoad() {
    WebDriverWait wait = new WebDriverWait(driver, 10);
    wait.until(ExpectedConditions.presenceOfElementLocated(By.id("tbodycars")));
}

From source file:WaitTool.java

License:Open Source License

/**
 * Wait for the element to be present in the DOM, regardless of being displayed or not.
 * And returns the first WebElement using the given method.
 *
 * @param WebDriver   The driver object to be used
 * @param By   selector to find the element
 * @param int   The time in seconds to wait until returning a failure
 *
 * @return WebElement   the first WebElement using the given method, or null (if the timeout is reached)
 *//*from   w  ww.  ja  v a 2s. co  m*/
public static WebElement waitForElementPresent(WebDriver driver, final By by, int timeOutInSeconds) {
    WebElement element;
    try {
        driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait()

        WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
        element = wait.until(ExpectedConditions.presenceOfElementLocated(by));

        driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait
        return element; //return the element
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:be.rubus.web.testing.AbstractWidget.java

License:Apache License

protected void presenceOfElementLocated(By byId) {
    new WebDriverWait(driver, 5).until(ExpectedConditions.presenceOfElementLocated(byId));
}

From source file:bg.pragmatic.lecture13mvn.waits.utils.WaitTool.java

License:Open Source License

/**
 * Wait for the element to be present in the DOM, regardless of being
 * displayed or not. And returns the first WebElement using the given
 * method.//from   w ww .j a  va  2s.c  o m
 * 
 * @param WebDriver
 *            The driver object to be used
 * @param By
 *            selector to find the element
 * @param int The time in seconds to wait until returning a failure
 * 
 * @return WebElement the first WebElement using the given method, or null
 *         (if the timeout is reached)
 */
public static WebElement waitForElementPresent(WebDriver driver, final By by, int timeOutInSeconds) {
    WebElement element;
    try {
        driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); // nullify
        // implicitlyWait()

        WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
        element = wait.until(ExpectedConditions.presenceOfElementLocated(by));

        driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); // reset
        // implicitlyWait
        return element; // return the element
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:bi.com.seleniumgrid.PhantomJsTest.java

License:Apache License

@Test
public void test() {
    final DesiredCapabilities capabilities = new DesiredCapabilities();
    // Configure our WebDriver to support JavaScript and be able to find the PhantomJS binary
    capabilities.setJavascriptEnabled(true);
    capabilities.setCapability("takesScreenshot", false);
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, PHANTOMJS_BINARY);
    final WebDriver driver = new PhantomJSDriver(capabilities);
    // Your test code here. For example:
    WebDriverWait wait = new WebDriverWait(driver, 30); // 30 seconds of timeout
    driver.get("https://en.wikipedia.org/wiki/Main_Page"); // navigate to Wikipedia

    pageTitle = driver.getTitle().trim();
    Assert.assertEquals(pageTitle, "GoalQuest");

    System.out.println("Page title is: " + driver.getTitle());

    By searchInput = By.id("searchInput"); // search for "Software"
    wait.until(ExpectedConditions.presenceOfElementLocated(searchInput));
    driver.findElement(searchInput).sendKeys("Software");
    By searchButton = By.id("searchButton");
    wait.until(ExpectedConditions.elementToBeClickable(searchButton));
    driver.findElement(searchButton).click();

    wait.until(ExpectedConditions.textToBePresentInElementLocated(By.tagName("body"), "Computer software")); // assert that the resulting page contains a text
}

From source file:br.com.mundotigre.scripts.WaitTool.java

License:Open Source License

/**
* Wait for the element to be present in the DOM, regardless of being displayed or not.
* And returns the first WebElement using the given method.
*
* @param WebDriver   The driver object to be used 
* @param By   selector to find the element
* @param int   The time in seconds to wait until returning a failure
* 
* @return WebElement   the first WebElement using the given method, or null (if the timeout is reached)
*///from  w w  w .  ja  v a 2s  .  c o m
public static WebElement waitForElementPresent(WebDriver driver, final By by, int timeOutInSeconds) {
    WebElement element;
    try {
        driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() 

        WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
        element = wait.until(ExpectedConditions.presenceOfElementLocated(by));

        driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait
        return element; //return the element
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.ui.WebBase.java

License:Open Source License

/**
 * Mtodo que verifica em todas as classes se existe um componente Loading,
 * e se existir, ele sempre espera que este elemento desaparea antes de
 * continuar./* ww w  .j  a v a 2s. c om*/
 */
@SuppressWarnings("unchecked")
public void waitLoading() {

    driver = (WebDriver) runner.getDriver();

    driver.manage().timeouts().implicitlyWait(0, TimeUnit.MILLISECONDS);

    if (!alreadySearchLoadingMap) {

        alreadySearchLoadingMap = true;

        Reflections reflections = new Reflections("");
        Set<Class<?>> annotatedClasses = reflections.getTypesAnnotatedWith(ScreenMap.class);

        for (Class<?> clazzI : annotatedClasses) {
            HashSet<Field> fields = (HashSet<Field>) ReflectionUtils.getAllFields(clazzI,
                    ReflectionUtils.withAnnotation(ElementMap.class),
                    ReflectionUtils.withTypeAssignableTo(Loading.class));

            if (fields.size() == 1) {
                for (Field field : fields) {
                    loadingMap = field.getAnnotation(ElementMap.class);
                }
            }
        }

    }

    if (loadingMap != null) {

        boolean existeLoading;

        try {
            // Verifica se existe o LOADING
            ExpectedConditions
                    .presenceOfElementLocated(
                            ByConverter.convert(loadingMap.locatorType(), loadingMap.locator()[0]))
                    .apply(driver);
            existeLoading = true;

            log.debug(message.getString("message-loading-visible"));
        } catch (Exception e) {
            existeLoading = false;
        }

        if (existeLoading) {
            // Fora esperar o loading aparecer quando o elemento utilizado
            // tem a propriedade forWaitLoading na anotao @ElementMap
            if (getElementMap() != null && getElementMap().forceWaitLoading()) {
                WebDriverWait wait = new WebDriverWait(getDriver(),
                        (BehaveConfig.getRunner_ScreenMaxWait() / 1000));
                wait.until(ExpectedConditions.visibilityOfElementLocated(
                        ByConverter.convert(loadingMap.locatorType(), loadingMap.locator()[0])));

                log.debug(message.getString("message-force-loading"));
            }

            // Aguardo o LOADING desaparecer!
            WebDriverWait wait = new WebDriverWait(getDriver(),
                    (BehaveConfig.getRunner_ScreenMaxWait() / 1000));
            wait.until(ExpectedConditions.invisibilityOfElementLocated(
                    ByConverter.convert(loadingMap.locatorType(), loadingMap.locator()[0])));

            log.debug(message.getString("message-loading-invisible"));
        }

    }

    driver.manage().timeouts().implicitlyWait(BehaveConfig.getRunner_ScreenMaxWait(), TimeUnit.MILLISECONDS);
}

From source file:ca.nrc.cadc.web.selenium.AbstractTestWebPage.java

License:Open Source License

protected void clearTextInput(final By by) throws Exception {
    final WebElement inputElement = waitUntil(ExpectedConditions.presenceOfElementLocated(by));

    // Focus issues.
    hover(by);/*  ww w  . ja  v a2s .com*/
    inputElement.click();
    inputElement.clear();
}

From source file:ca.nrc.cadc.web.selenium.AbstractTestWebPage.java

License:Open Source License

public WebElement waitForElementPresent(final By by) throws Exception {
    return waitUntil(ExpectedConditions.presenceOfElementLocated(by));
}

From source file:ca.nrc.cadc.web.selenium.AbstractWebApplicationIntegrationTest.java

License:Open Source License

public void waitForElementPresent(final By by) throws Exception {
    if (waitUntil(ExpectedConditions.presenceOfElementLocated(by)) == null) {
        fail("Could not find " + by.toString());
    }/* www  . ja  v a  2 s . co  m*/
}