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

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

Introduction

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

Prototype

public static ExpectedCondition<List<WebElement>> presenceOfAllElementsLocatedBy(final By locator) 

Source Link

Document

An expectation for checking that there is at least one element present on a web page.

Usage

From source file:org.apache.geode.tools.pulse.tests.ui.PulseTestUtils.java

License:Apache License

public static void verifyElementPresentById(String id) {
    WebDriverWait wait = new WebDriverWait(getDriver(), maxWaitTime, 500);
    wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.id(id)));
}

From source file:org.apache.geode.tools.pulse.tests.ui.PulseTestUtils.java

License:Apache License

public static void verifyElementPresentByLinkText(String lnkText) {
    WebDriverWait wait = new WebDriverWait(getDriver(), maxWaitTime, 500);
    wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.linkText(lnkText)));
}

From source file:org.apache.geode.tools.pulse.tests.ui.PulseTestUtils.java

License:Apache License

public static void verifyElementPresentByXpath(String xpath) {
    WebDriverWait wait = new WebDriverWait(getDriver(), maxWaitTime, 500);
    wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(xpath)));
}

From source file:org.craftercms.web.basic.ComponentTest.java

@Test
public void testDragAndDrop() throws InterruptedException {
    String image = "/requiredImage.png";

    // Navigate to About page
    //driver.navigate().to(seleniumProperties.getProperty("craftercms.base.url") + aboutPage);
    CStudioSeleniumUtil.navigateToAndWaitForPageToLoad(driver,
            seleniumProperties.getProperty("craftercms.base.url") + aboutPage);

    CStudioSeleniumUtil.clickOn(driver, By.cssSelector("#acn-preview-tools-container"));

    new WebDriverWait(driver, 10).until(new ExpectedCondition<Boolean>() {
        @Override/*from w w  w . j  av  a 2  s.co m*/
        public Boolean apply(WebDriver d) {
            return d.findElement(By.cssSelector("#preview-tools-panel-container")).isDisplayed();
        }
    });

    List<WebElement> options = (new WebDriverWait(driver, 10)).until(ExpectedConditions
            .presenceOfAllElementsLocatedBy(By.cssSelector("#preview-tools-panel-container .contracted")));

    options.get(1).click();

    new WebDriverWait(driver, 10).until(new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver d) {
            return d.findElement(By.id("placeholder-zone-bottomPromos1")).isDisplayed();
        }
    });

    WebElement source = driver.findElement(By.id("yui-gen4"));
    WebElement target = driver.findElement(By.id("bottomPromos1"));

    Actions builder = new Actions(driver);
    Action dragAndDrop = builder.dragAndDrop(source, target).build();
    dragAndDrop.perform();

    WebElement element = (new WebDriverWait(driver, 10))
            .until(ExpectedConditions.presenceOfElementLocated(By.id("in-context-edit-editor")));
    //Check the modal window
    assertTrue(element != null);

    driver.switchTo().frame(element);

    //Upload an Image
    CStudioSeleniumUtil.clickOn(driver, By.cssSelector("#image input[value='Add']"));

    element = (new WebDriverWait(driver, 10))
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("#cstudio-wcm-popup-div")));
    //Check the modal window
    assertTrue(element != null);

    driver.findElement(By.cssSelector("#uploadFileNameId")).sendKeys(assetsPath + image);
    driver.findElement(By.cssSelector("#uploadButton")).click();

    new WebDriverWait(driver, 10).until(new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver d) {
            return !d.findElement(By.cssSelector("#image .datum")).getAttribute("value").isEmpty();
        }
    });

    driver.findElement(By.cssSelector("#cstudioSaveAndClose")).click();

    driver.switchTo().defaultContent();
}

From source file:org.cybercat.automation.components.GroupElements.java

License:Apache License

@Override
public void initWebElement(Browser browser) throws PageObjectException {
    if (getState().equals(ElementState.CREATED)) {
        processor.initWebElementByCriteria(browser, new AbstractCriteria<List<WebElement>>(getPath()) {

            @Override/*  w  ww.  j a v a2 s . c  o m*/
            public ExpectedCondition<List<WebElement>> getExpectedCondition(String path) {
                return ExpectedConditions.presenceOfAllElementsLocatedBy(processor.getByElement(path));
            }

            @Override
            public boolean onSuccess(List<WebElement> elements, String path) {
                if (elements != null && elements.size() > 0) {
                    setActualPath(path);
                    int i = 0;
                    for (WebElement element : elements) {
                        subElements.add(createNewElement(path, i++, element));
                    }
                    return true;
                }
                return false;
            }

        });
        if (subElements.size() == 0) {
            log.error("element \"" + getName() + "\" is not found ");
            throw new PageObjectException("element \"" + getName() + "\" is not found.");
        }
        setState(ElementState.INITIALIZED);
    }

}

From source file:org.cybercat.automation.components.PageElement.java

License:Apache License

/**
 * @param driver/*from  www . j  av a 2 s .  c  om*/
 * @throws PageObjectException
 */
public void initWebElement(final Browser browser) throws PageObjectException {
    if (state.equals(ElementState.CREATED)) {
        try {
            browser.callImplicitlyWait(processor.implicitTimeout);
            processor.initWebElementByCriteria(browser, new AbstractCriteria<List<WebElement>>(path) {

                @Override
                public ExpectedCondition<List<WebElement>> getExpectedCondition(String path) {
                    return ExpectedConditions.presenceOfAllElementsLocatedBy(processor.getByElement(path));
                }

                @Override
                public boolean onSuccess(List<WebElement> elements, String path) {
                    if (elements != null && elements.size() > 0) {
                        actualPath = path;
                        element = elements.get(0);
                        browser.highlightElement(element);
                        setState(ElementState.INITIALIZED);
                        return true;
                    }
                    return false;
                }
            });
        } catch (Exception e) {
            log.error("element \"" + name + "\" is not found ");
            throw new PageObjectException("Element \"" + name + "\" is not found. By path: " + getActualPath(),
                    e);
        }
        if (element == null)
            throw new PageObjectException(
                    "Element \"" + name + "\" is not found on page. By path: " + getActualPath());
        if (!waitPresent())
            throw new PageObjectException(
                    "\"" + getName() + "\" element is not visible by path " + getActualPath());
    }

}

From source file:org.cybercat.automation.components.PageElement.java

License:Apache License

/**
 * Intention of this method is to initialize PageElement object based on
 * partial locator (that returns list of similar WebElements) and text
 * contained in the WebElement/*from   ww w  .j a v a 2s. c o  m*/
 * 
 * @param browser
 * @param text
 * @throws PageObjectException
 */
public void initWebElement(final Browser browser, final String text) throws PageObjectException {
    if (state.equals(ElementState.CREATED)) {
        try {
            processor.initWebElementByCriteria(browser, new AbstractCriteria<List<WebElement>>(path) {

                @Override
                public ExpectedCondition<List<WebElement>> getExpectedCondition(String path) {
                    return ExpectedConditions.presenceOfAllElementsLocatedBy(processor.getByElement(path));
                }

                @Override
                public boolean onSuccess(List<WebElement> elements, String path) {
                    for (WebElement thisElement : elements) {
                        String innerText = (String) browser.executeScript("return arguments[0].textContent",
                                thisElement);
                        System.out.println(thisElement.toString() + " +++ " + innerText + " +++ " + text);
                        if (StringUtils.containsIgnoreCase(innerText, text)) {
                            actualPath = path;
                            element = thisElement;
                            browser.highlightElement(element);
                            setState(ElementState.INITIALIZED);
                            return true;
                        }
                    }
                    return false;
                }
            });
        } catch (Exception e) {
            log.error("element \"" + name + "\" is not found ");
            throw new PageObjectException("element \"" + name + "\" is not found by text: \"" + text + "\"", e);
        }
        if (element == null)
            throw new PageObjectException("element \"" + name + "\" is not found. By Path:" + getActualPath());
        if (!waitPresent())
            throw new PageObjectException("\"" + getName() + "\" element is not visible by path "
                    + getActualPath() + "  and text: " + text);
    }

}

From source file:org.cybercat.automation.components.VisibleTextField.java

License:Apache License

@Override
public void initWebElement(final Browser browser) throws PageObjectException {
    if (getState().equals(ElementState.CREATED)) {
        try {// w  w w .j  av a2  s.  c om
            processor.initWebElementByCriteria(browser, new AbstractCriteria<List<WebElement>>(path) {

                @Override
                public ExpectedCondition<List<WebElement>> getExpectedCondition(String path) {
                    return ExpectedConditions.presenceOfAllElementsLocatedBy(processor.getByElement(path));
                }

                @Override
                public boolean onSuccess(List<WebElement> elements, String path) {
                    if (elements != null && elements.size() > 0) {
                        setActualPath(path);
                        setState(ElementState.INITIALIZED);
                        for (WebElement innerElement : elements) {
                            setElement(innerElement);
                            if (getElement().isDisplayed()) {
                                browser.highlightElement(getElement());
                                return true;
                            }
                        }
                    }
                    return false;
                }
            });
        } catch (Exception e) {
            log.error("element \"" + name + "\" is not found ");
            throw new PageObjectException("element \"" + name + "\" is not found.", e);
        }
        if (getElement() == null)
            throw new PageObjectException("element \"" + name + "\" is not found.");
        if (!waitPresent())
            throw new PageObjectException(
                    "\"" + getName() + "\" element is not visible by path " + getActualPath());
    }
    //TODO: ???!!!
    super.initWebElement(browser);
}

From source file:org.cybercat.automation.components.VisibleTextField.java

License:Apache License

@Override
public void initWebElement(final Browser browser, final String text) throws PageObjectException {
    if (getState().equals(ElementState.CREATED)) {
        try {// www.j ava  2 s . co  m
            processor.initWebElementByCriteria(browser, new AbstractCriteria<List<WebElement>>(path) {

                @Override
                public ExpectedCondition<List<WebElement>> getExpectedCondition(String path) {
                    return ExpectedConditions.presenceOfAllElementsLocatedBy(processor.getByElement(path));
                }

                @Override
                public boolean onSuccess(List<WebElement> elements, String path) {
                    for (WebElement thisElement : elements) {
                        String innerText = (String) browser.executeScript("return arguments[0].textContent",
                                thisElement);
                        System.out.println(thisElement.toString() + " +++ " + innerText + " +++ " + text);
                        if (StringUtils.containsIgnoreCase(innerText, text)) {
                            setActualPath(path);
                            setElement(thisElement);
                            setState(ElementState.INITIALIZED);
                            if (getElement().isDisplayed()) {
                                browser.highlightElement(getElement());
                                return true;
                            }
                        }
                    }
                    return false;
                }
            });
        } catch (Exception e) {
            log.error("element \"" + name + "\" is not found ");
            throw new PageObjectException("element \"" + name + "\" is not found by text: \"" + text + "\"", e);
        }
        if (getElement() == null)
            throw new PageObjectException("element \"" + name + "\" is not found.");
        if (!waitPresent())
            throw new PageObjectException(
                    "\"" + getName() + "\" element is not visible by path " + getActualPath());
    }
    //TODO: ???!!!
    super.initWebElement(browser, text);
}

From source file:org.eclipse.che.selenium.languageserver.CheckMainFeatureForCSharpLanguageTest.java

License:Open Source License

private boolean isLanguageServerInitFailed() {
    String xpathLocatorForEventMessages = "//div[contains(@id,'gwt-debug-notification-wrappergwt-uid')]";
    List<WebElement> textMessages = new WebDriverWait(seleniumWebDriver, MINIMUM_SEC)
            .until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(xpathLocatorForEventMessages)));
    return textMessages.stream()
            .anyMatch(message -> message.getAttribute("textContent").contains("Timeout initializing error"));
}