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:com.github.wasiqb.coteafs.appium.device.DeviceActivity.java

License:Apache License

/**
 * @author wasiq.bhamla//  w  w w .  ja v  a  2s  . c o  m
 * @since Jan 30, 2018 7:33:47 PM
 * @param locator
 * @param waitStrategy
 */
private void wait(final By locator, final WaitStrategy waitStrategy) {
    switch (waitStrategy) {
    case ENABLED:
        this.wait.until(ExpectedConditions.elementToBeClickable(locator));
        break;
    case PRESENT:
        this.wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(locator));
        break;
    case VISIBLE:
        this.wait.until(visibilityOfAllElementsLocatedBy(locator));
        break;
    case NONE:
    default:
        break;
    }
}

From source file:com.gumtreescraper.scraper.GumtreeScraper.java

public void scrapeWithClick(List<Gumtree> gumtrees, String url) {

    openSite(url);/*from w  ww  .j a  va  2 s .co  m*/
    waitForPageToLoad();

    do {
        List<WebElement> gumtreeAds = (new WebDriverWait(this.webDriver, getTimeout()))
                .until(ExpectedConditions.presenceOfAllElementsLocatedBy(
                        By.xpath("//ul[@id='srchrslt-adtable']/li//h6[@class='rs-ad-title']/a")));

        for (WebElement ad : gumtreeAds) {
            //                String adUrl = (new WebDriverWait(this.webDriver, 15))
            //            .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//h6[@class='rs-ad-title']/a"))).getAttribute("href");
            //                String adUrl = ad.findElement(By.xpath("//h6[@class='rs-ad-title']/a")).getAttribute("href");
            String adUrl = ad.getAttribute("href");
            Gumtree gumtree = new Gumtree();
            gumtree.setUrl(adUrl);
            gumtrees.add(gumtree);
        }

        List<WebElement> nextElements = webDriver.findElements(By.xpath("//a[@class='rs-paginator-btn next']"));
        if (nextElements.isEmpty()) { //  no more next page
            break;
        }

        nextElements.get(0).click();
        try {
            Thread.sleep(5000);

        } catch (InterruptedException ex) {
            Logger.getLogger(GumtreeScraper.class.getName()).log(Level.SEVERE, null, ex);
        }

    } while (true);
}

From source file:com.gumtreescraper.scraper.GumtreeScraper.java

public void scrape(List<Gumtree> gumtrees, String url) {

    // get total page
    int totalPage = getTotalPage(url);

    for (int i = 1; i <= totalPage; i++) {

        String newUrl = buildPageUrl(url, i);
        //            openSiteWithoutTimeout(newUrl);
        openSite(newUrl);/*from  ww  w  . j  a  v  a 2 s . co m*/
        waitForPageToLoad();

        if (i == 1) {
            try {
                Thread.sleep(20 * 1000);
            } catch (InterruptedException ex) {
                Logger.getLogger(GumtreeScraper.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        //            List<WebElement> gumtreeAds = (new WebDriverWait(this.webDriver, 15))
        //            .until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//ul[@id='srchrslt-adtable']/li")));

        List<WebElement> gumtreeAds = (new WebDriverWait(this.webDriver, SPECIAL_TIMEOUT))
                .until(ExpectedConditions.presenceOfAllElementsLocatedBy(
                        By.xpath("//ul[@id='srchrslt-adtable']/li//h6[@class='rs-ad-title']/a")));

        for (WebElement ad : gumtreeAds) {
            //               (new WebDriverWait(this.webDriver, 15))
            //            .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//h6[@class='rs-ad-title']/a")));

            try {
                //                    String adUrl = ad.findElement(By.xpath("//h6[@class='rs-ad-title']/a")).getAttribute("href");
                String adUrl = ad.getAttribute("href");
                Gumtree gumtree = new Gumtree();
                gumtree.setUrl(adUrl);
                gumtrees.add(gumtree);
            } catch (StaleElementReferenceException ex) {
                ex.printStackTrace();
                String adUrl = ad.findElement(By.xpath("//h6[@class='rs-ad-title']/a")).getAttribute("href");
                Gumtree gumtree = new Gumtree();
                gumtree.setUrl(adUrl);
                gumtrees.add(gumtree);
            }
        }

        //            List<WebElement> nextElements = webDriver.findElements(By.xpath("//a[@class='rs-paginator-btn next']"));
        //            if (nextElements.isEmpty()) { //  no more next page
        //                break;
        //            }
        //
        //            nextElements.get(0).click();
    }

    //        List<WebElement> lastPageElements = webDriver.findElements(By.xpath("//a[@class='rs-paginator-btn last']"));
    //        if (lastPageElements.isEmpty()) { // 1 page only
    //            return;
    //        }
    //                
    //        do {
    //            List<WebElement> gumtreeAds = (new WebDriverWait(this.webDriver, 15))
    //            .until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//ul[@id='srchrslt-adtable']/li")));
    //                      
    //            for (WebElement ad : gumtreeAds) {
    //                String adUrl = (new WebDriverWait(this.webDriver, 15))
    //            .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//h6[@class='rs-ad-title']/a"))).getAttribute("href");
    ////                String adUrl = ad.findElement(By.xpath("//h6[@class='rs-ad-title']/a")).getAttribute("href");
    //                Gumtree gumtree = new Gumtree();
    //                gumtree.setUrl(adUrl);
    //                gumtrees.add(gumtree);
    //            }
    //
    //            List<WebElement> nextElements = webDriver.findElements(By.xpath("//a[@class='rs-paginator-btn next']"));
    //            if (nextElements.isEmpty()) { //  no more next page
    //                break;
    //            }
    //
    //            nextElements.get(0).click();
    //
    ////        scrape(gumtrees, nextPageUrl);
    //        
    //        } while(true);
}

From source file:com.hotwire.selenium.desktop.us.billing.car.impl.ccf.CcfAddFeaturesFragment.java

License:Open Source License

@Override
public List<WebElement> getTripInsuranceRadioFields() {
    new WebDriverWait(getWebDriver(), 10).until(ExpectedConditions
            .presenceOfAllElementsLocatedBy(By.xpath(".//*[@id='carSpaInsurance']//input[@type='radio']")));
    return getWebDriver().findElements(By.xpath(".//*[@id='carSpaInsurance']//input[@type='radio']"));
}

From source file:com.hotwire.selenium.desktop.us.partners.PartnerIMLFragment.java

License:Open Source License

public void selectPartnerOnIML(int partner) {
    List<WebElement> partnerCb = new WebDriverWait(getWebDriver(), 20)
            .until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.cssSelector(PARTNER_CHECKBOX_CSS)));
    partnerCb.get(partner).click();//  ww  w  .  ja  v a  2  s  .com
}

From source file:com.hotwire.selenium.desktop.widget.DropDownSelector.java

License:Open Source License

/**
 * Select item from drop-down by its visible text
 *//*from   w w w  .  j ava  2  s  .c  om*/
public void selectByVisibleText(String itemText) {

    if (StringUtils.isEmpty(itemText)) {
        return;
    }

    if (nativeDropDown.isDisplayed()) {
        Select startTimeCarSelect = new Select(nativeDropDown);
        startTimeCarSelect.selectByVisibleText(itemText);
        return;
    }

    By href = By.cssSelector(String.format("a[id^='%s']", nativeDropDown.getAttribute("id")));

    new WebDriverWait(webDriver, TIMEOUT).until(ExpectedConditions.presenceOfAllElementsLocatedBy(href));

    WebElement customDropDown = webDriver.findElement(href);
    customDropDown.click();
    customDropDown.sendKeys(Keys.HOME);
    By elementSelector = By.xpath("//div[contains(@class,'ui-selectmenu-open')]//a[text()='" + itemText + "']");
    WebElement element = webDriver.findElement(elementSelector);
    element.click();
}

From source file:com.liferay.faces.bridge.test.integration.issue.FACES_1470PortletTester.java

License:Open Source License

@Test
public void runFACES_1470PortletTest() {

    String container = TestUtil.getContainer();
    Assume.assumeTrue("The FACES-1470 test is only valid on Liferay Portal.", container.startsWith("liferay"));

    // 1. Sign in to the portal.
    BrowserDriver browserDriver = getBrowserDriver();
    browserDriver.navigateWindowTo(BridgeTestUtil.getIssuePageURL("faces-1470"));

    String navigateToView1LinkXpath = "//a[contains(text(), 'Navigate to view1.xhtml')]";
    browserDriver.waitForElementEnabled(navigateToView1LinkXpath);

    // 2. Open the *Navigate to view1.xhtml* link in a new tab.
    String as7LeakInstanceTrackerWindowId = browserDriver.getCurrentWindowId();
    Set<String> windowIds = browserDriver.getWindowIds();
    int numberOfWindows = windowIds.size();
    browserDriver.clickElement(navigateToView1LinkXpath);
    browserDriver.waitFor(new WindowOpened(numberOfWindows));
    windowIds = browserDriver.getWindowIds();

    // 3. Switch back to the first tab (as7LeakTracker.xhtml) and click the *Refresh AS7Leak List* button and
    // confirm that several AS7Leak class instances appear.
    Iterator<String> iterator = windowIds.iterator();
    String viewsWindowId = null;//  w ww .  j a va  2s  . c o  m

    while (iterator.hasNext()) {

        String windowId = iterator.next();

        if (!as7LeakInstanceTrackerWindowId.equals(windowId)) {

            viewsWindowId = windowId;

            break;
        }
    }

    if (viewsWindowId == null) {
        throw new IllegalStateException("No new tab opened when *Navigate to view1.xhtml* was clicked.");
    }

    WaitingAsserter waitingAsserter = getWaitingAsserter();
    List<WebElement> as7LeakInstanceElements = new ArrayList<WebElement>();
    testAS7LeakIntancesCreated(browserDriver, waitingAsserter, as7LeakInstanceTrackerWindowId,
            as7LeakInstanceElements);

    // 4. Switch back to the tab with view1.xhtml and click the *Click me to navigate to view2.xhtml via Ajax*
    // button.
    switchToWindow(browserDriver, viewsWindowId);

    String navToView2AjaxButtonXpath = "//input[contains(@value,'Click me to navigate to view2.xhtml via Ajax')]";
    clickButton(browserDriver, navToView2AjaxButtonXpath);

    // 5. Click the *Click me to navigate to view1.xhtml via Ajax* button.
    String navToView1AjaxButtonXpath = "//input[contains(@value,'Click me to navigate to view1.xhtml via Ajax')]";
    clickButton(browserDriver, navToView1AjaxButtonXpath);

    // 6. Switch back to the first tab (as7LeakTracker.xhtml) and click the Refresh AS7Leak List button and confirm
    // that several AS7Leak class instances appear.
    testAS7LeakIntancesCreated(browserDriver, waitingAsserter, as7LeakInstanceTrackerWindowId,
            as7LeakInstanceElements);

    // 7. Switch back to the tab with view1.xhtml and click the *Click me to navigate to view2.xhtml via non-Ajax
    // (full postback)* button.
    switchToWindow(browserDriver, viewsWindowId);

    String navToView2NonAjaxButtonXpath = "//input[contains(@value,'Click me to navigate to view2.xhtml via non-Ajax (full postback)')]";
    clickButton(browserDriver, navToView2NonAjaxButtonXpath);

    // 8. Click the *Click me to navigate to view1.xhtml via non-Ajax (full postback)* button.
    String navToView1NonAjaxButtonXpath = "//input[contains(@value,'Click me to navigate to view1.xhtml via non-Ajax (full postback)')]";
    clickButton(browserDriver, navToView1NonAjaxButtonXpath);

    // 9. Switch back to the first tab (as7LeakTracker.xhtml) and click the *Refresh AS7Leak List* button and
    // confirm that several AS7Leak class instances appear.
    testAS7LeakIntancesCreated(browserDriver, waitingAsserter, as7LeakInstanceTrackerWindowId,
            as7LeakInstanceElements);

    // 10. Switch back to the tab with view1.xhtml and click the *Click me to navigate to view2.xhtml via Ajax*
    // button.
    switchToWindow(browserDriver, viewsWindowId);
    clickButton(browserDriver, navToView2AjaxButtonXpath);

    // 11. Click the *Click me to navigate to view1.xhtml via non-Ajax (full postback)* button.
    clickButton(browserDriver, navToView1NonAjaxButtonXpath);

    // 12. Switch back to the first tab (as7LeakTracker.xhtml) and click the *Refresh AS7Leak List* button and
    // confirm that several AS7Leak class instances appear.
    testAS7LeakIntancesCreated(browserDriver, waitingAsserter, as7LeakInstanceTrackerWindowId,
            as7LeakInstanceElements);

    // 13. Switch back to the tab with view1.xhtml and click the *Click me to navigate to view2.xhtml via non-Ajax
    // (full postback)* button.
    switchToWindow(browserDriver, viewsWindowId);
    clickButton(browserDriver, navToView2NonAjaxButtonXpath);

    // 14. Click the *Click me to navigate to view1.xhtml via Ajax* button.
    clickButton(browserDriver, navToView1AjaxButtonXpath);

    // 15. Switch back to the first tab (as7LeakTracker.xhtml) and click the *Refresh AS7Leak List* button and
    // confirm that several AS7Leak class instances appear.
    testAS7LeakIntancesCreated(browserDriver, waitingAsserter, as7LeakInstanceTrackerWindowId,
            as7LeakInstanceElements);

    // 16. Switch back to the tab with view1.xhtml, navigate to the as7LeakTracker.xhtml portlet page (to avoid
    // loading any AS7Leak instances as an unauthenticated user), and sign out of the portal.
    switchToWindow(browserDriver, viewsWindowId);
    browserDriver.navigateWindowTo(BridgeTestUtil.getIssuePageURL("faces-1470"));
    signOut(browserDriver);
    browserDriver.closeCurrentWindow();

    // 17. Switch back to the first tab (as7LeakTracker.xhtml) and click the *Refresh AS7Leak List* button and
    // confirm that several AS7Leak class instances appear.
    testAS7LeakIntancesCreated(browserDriver, waitingAsserter, as7LeakInstanceTrackerWindowId,
            as7LeakInstanceElements);

    // 18. Click the *Perform Garbage Collection* button and confirm that no AS7Leak class instances appear. Note:
    // since this portlet uses System.gc() to initiate garbage collection, it may be necessary to click the *Perform
    // Garbage Collection* multiple times before the garbage is actually collected. For more details see here:
    // http://docs.oracle.com/javase/6/docs/api/java/lang/System.html#gc().
    ExpectedCondition<Boolean> as7LeakElementsNotPresent = ExpectedConditions
            .not(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(as7LeakInstanceXpath)));

    // Attempt garbage collection 5 times before giving up.
    for (int i = 0; i < 5; i++) {

        clickButton(browserDriver, "//input[contains(@value,'Perform Garbage Collection')]");

        try {

            browserDriver.waitFor(as7LeakElementsNotPresent);

            break;
        } catch (TimeoutException e) {
            // Retry.
        }
    }

    waitingAsserter.assertElementNotPresent(as7LeakInstanceXpath);
}

From source file:com.liferay.faces.test.AlloyApplicantPortletTest.java

License:Open Source License

@Test
@RunAsClient/*from  w w  w .  ja  v a  2s. c o m*/
@InSequence(2000)
public void validateEmail() throws Exception {

    String foo = "";

    // checks an invalid email address
    logger.log(Level.INFO, "Entering an invalid email address 'test' ...");
    emailAddressField.sendKeys("test");
    phoneNumberField.click();

    logger.log(Level.INFO, "Waiting for the emailAddressFieldError to contain 'Invalid e-mail address' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(emailAddressFieldErrorXpath),
                "Invalid e-mail address"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        assertTrue("emailAddressField should be visible after tabbing out with no value," + " but "
                + emailAddressFieldErrorXpath + " is not visible.", false);
    }
    logger.log(Level.INFO,
            "emailAddressField.getAttribute('value') = " + emailAddressField.getAttribute("value"));

    assertTrue("Invalid e-mail address validation message displayed",
            emailAddressFieldError.getText().contains("Invalid e-mail address"));
    logger.log(Level.INFO, "emailAddressFieldError.isDisplayed() = " + emailAddressFieldError.isDisplayed());
    logger.log(Level.INFO, "emailAddressFieldError.getText() = " + emailAddressFieldError.getText());

    // checks a valid email address
    logger.log(Level.INFO, "Waiting for the emailAddressFieldError to contain '' ...");
    try {
        emailAddressField.clear();
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(emailAddressFieldXpath), ""));
        logger.log(Level.INFO, "emailAddressField.getText() = '" + emailAddressField.getText() + "'");
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, emailAddressFieldXpath)) {
            foo = emailAddressField.getText();
        }
        assertTrue("emailAddressField should be clear," + " but " + emailAddressFieldXpath + " contains '" + foo
                + "'", false);
    }

    logger.log(Level.INFO, "Entering a valid email address 'test@liferay.com' ...");
    emailAddressField.click();
    emailAddressField.sendKeys("test@liferay.com");
    emailAddressField.sendKeys(Keys.TAB);
    phoneNumberField.click();

    logger.log(Level.INFO, "Waiting for the emailAddressField to contain 'test@liferay.com' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(emailAddressFieldXpath),
                "test@liferay.com"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, emailAddressFieldXpath)) {
            foo = emailAddressField.getText();
        }
        assertTrue("emailAddressField should contain 'test@liferay.com'," + " but " + emailAddressFieldXpath
                + " contains '" + foo + "'", false);
    }

    logger.log(Level.INFO, "Waiting for the emailAddressFieldError to disappear ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions
                .not(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(emailAddressFieldErrorXpath))));
        logger.log(Level.INFO,
                "emailAddressField.getAttribute('value') = " + emailAddressField.getAttribute("value"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, emailAddressFieldErrorXpath)) {
            foo = emailAddressFieldError.getText();
        }
        assertTrue("emailAddressFieldError should NOT be visible after entering 'test@liferay.com'," + " but "
                + emailAddressFieldErrorXpath + " is still there showing '" + foo + "'", false);
    }

}

From source file:com.liferay.faces.test.AlloyApplicantPortletTest.java

License:Open Source License

@Test
@RunAsClient//from   w  ww  . j a va2 s.  c o  m
@InSequence(8000)
public void dateValidation() throws Exception {

    String foo = "";

    // checks an invalid dateOfBirth
    try {
        dateOfBirthField.clear();
        logger.log(Level.INFO, "No exceptions occured when clearing the dateOfBirthField");
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        assertTrue(
                "No exceptions should occur when clearing the dateOfBirthField, but one did occur with the following message: "
                        + e.getMessage(),
                false);
    }

    logger.log(Level.INFO, "Waiting for the dateOfBirthField to contain '' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(dateOfBirthFieldXpath), ""));
        logger.log(Level.INFO, "after clearing dateOfBirthField.getAttribute('value') = "
                + dateOfBirthField.getAttribute("value"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, dateOfBirthFieldErrorXpath)) {
            foo = dateOfBirthFieldError.getText();
        }
        assertTrue("dateOfBirthField should be empty after clearing," + " but " + dateOfBirthFieldXpath
                + " contains '" + foo + "'.", false);
    }

    logger.log(Level.INFO, "Entering an invalid value for the date of birth ... 12/34/5678 ...");
    dateOfBirthField.sendKeys("12/34/5678");

    logger.log(Level.INFO, "Waiting for the dateOfBirthField to contain '12/34/5678' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(dateOfBirthFieldXpath),
                "12/34/5678"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, dateOfBirthFieldErrorXpath)) {
            foo = dateOfBirthFieldError.getText();
        }
        assertTrue("dateOfBirthField should contain '12/34/5678'," + " but " + dateOfBirthFieldXpath
                + " contains '" + foo + "'.", false);
    }

    submitButton.click();

    logger.log(Level.INFO, "Waiting for the dateOfBirthFieldError to contain 'Invalid date format' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(dateOfBirthFieldErrorXpath),
                "Invalid date format"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        assertTrue("dateOfBirthFieldError should be visible after submitting with '12/34/5678'," + " but "
                + dateOfBirthFieldErrorXpath + " is not visible.", false);
    }

    logger.log(Level.INFO,
            "dateOfBirthField.getAttribute('value') = " + dateOfBirthField.getAttribute("value"));
    logger.log(Level.INFO, "dateOfBirthFieldError.isDisplayed() = " + dateOfBirthFieldError.isDisplayed());
    logger.log(Level.INFO, "dateOfBirthFieldError.getText() = " + dateOfBirthFieldError.getText());
    assertTrue(
            "dateOfBirthFieldError should contain 'Invalid date format', but insteead contains '"
                    + dateOfBirthFieldError.getText() + "'",
            dateOfBirthFieldError.getText().contains("Invalid date format"));

    // checks with no dateOfBirth
    dateOfBirthField.clear();

    logger.log(Level.INFO, "Waiting for the dateOfBirthField to contain '' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(dateOfBirthFieldXpath), ""));
        logger.log(Level.INFO, "after clearing dateOfBirthField.getAttribute('value') = "
                + dateOfBirthField.getAttribute("value"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, dateOfBirthFieldErrorXpath)) {
            foo = dateOfBirthFieldError.getText();
        }
        assertTrue("dateOfBirthField should be empty after clearing," + " but " + dateOfBirthFieldXpath
                + " contains '" + foo + "'.", false);
    }

    phoneNumberField.click();

    logger.log(Level.INFO, "Waiting for the dateOfBirthFieldError to contain 'Value is required' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(dateOfBirthFieldErrorXpath),
                "Value is required"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        assertTrue(
                "dateOfBirthFieldError should be visible after entering '12/34/5678' and clicking into another field,"
                        + " but " + dateOfBirthFieldErrorXpath + " does not contain 'Value is required'.",
                false);
    }

    logger.log(Level.INFO,
            "dateOfBirthField.getAttribute('value') = " + dateOfBirthField.getAttribute("value"));
    logger.log(Level.INFO, "dateOfBirthFieldError.isDisplayed() = " + dateOfBirthFieldError.isDisplayed());
    logger.log(Level.INFO, "dateOfBirthFieldError.getText() = " + dateOfBirthFieldError.getText());

    // checks a valid dateOfBirth
    foo = "";
    dateOfBirthField.clear();

    logger.log(Level.INFO, "Waiting for the dateOfBirthField to contain '' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(dateOfBirthFieldXpath), ""));
        logger.log(Level.INFO, "after clearing dateOfBirthField.getAttribute('value') = "
                + dateOfBirthField.getAttribute("value"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, dateOfBirthFieldErrorXpath)) {
            foo = dateOfBirthFieldError.getText();
        }
        assertTrue("dateOfBirthField should be empty after clearing," + " but " + dateOfBirthFieldXpath
                + " contains '" + foo + "'.", false);
    }

    logger.log(Level.INFO, "Entering a valid dateOfBirth = 01/02/3456 ...");
    dateOfBirthField.sendKeys("01/02/3456");
    logger.log(Level.INFO, "Clicking into the phoneNumberField ...");
    phoneNumberField.click();

    logger.log(Level.INFO, "Waiting for the dateOfBirthFieldError to disappear ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions
                .not(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(dateOfBirthFieldErrorXpath))));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, dateOfBirthFieldErrorXpath)) {
            foo = dateOfBirthFieldError.getText();
        }
        assertTrue("dateOfBirthFieldError should NOT be visible after entering 01/02/3456," + " but "
                + dateOfBirthFieldErrorXpath + " is still there showing '" + foo + "'", false);
    }

}

From source file:com.liferay.faces.test.selenium.browser.internal.WaitingAsserterImpl.java

License:Open Source License

@Override
public void assertElementNotPresent(String elementXpath) {
    assertFalse(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(elementXpath)));
}