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:com.ggasoftware.uitest.utils.WebDriverWrapper.java

License:Open Source License

/**
 * Wait until link presents at web page.
 *
 * @param linkText       - linkText to be presents.
 * @param timeoutSec     to wait until presents.
 * @param checkCondition log assert for expected conditions.
 *///from   w  w  w.  j a va 2 s.c  om
public static void waitForLinkToBePresent(String linkText, int timeoutSec, boolean checkCondition) {
    ReporterNGExt.logAction(getDriver(), "", String.format("waitForLinkToBePresent: %s", linkText));
    boolean isPresent;
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    setTimeout(timeoutSec);
    try {
        wait.until(ExpectedConditions.presenceOfElementLocated(By.linkText(linkText)));
        isPresent = true;
    } catch (TimeoutException ignored) {
        ReporterNGExt.logTechnical(String.format("waitForLinkToBePresent: [ %s ] during: [ %d ] sec ", linkText,
                System.currentTimeMillis() / 1000 - start));
        isPresent = false;
    }
    setTimeout(TIMEOUT);
    if (checkCondition) {
        ReporterNGExt.logAssertTrue(ReporterNGExt.BUSINESS_LEVEL, isPresent,
                String.format("waitForLinkToBePresent: link with text '%s' should be exists", linkText),
                TestBaseWebDriver.takePassedScreenshot);
    }
}

From source file:com.github.seleniumpm.SeleniumWebdriver.java

License:Apache License

public Selenium waitForPresent(Object by, long waitTime) {
    WebDriverWait wait = new WebDriverWait(driver, TimeUnit.MILLISECONDS.toSeconds(waitTime));
    wait.until(ExpectedConditions.presenceOfElementLocated((By) by));
    return this;
}

From source file:com.github.seleniumpm.webelements.Element.java

License:Apache License

public Element waitForPresent(long waitTime) {
    WebDriverWait wait = new WebDriverWait(driver, TimeUnit.MILLISECONDS.toSeconds(waitTime));
    wait.until(ExpectedConditions.presenceOfElementLocated(locator));
    return this;
}

From source file:com.grok.utils.ReusableTests.java

License:Open Source License

public static void testSetUpProgressText(WebDriver driver) throws InterruptedException {
    WebDriverWait wait = new WebDriverWait(driver, WAIT_TIME);
    String str = wait.until(ExpectedConditions.presenceOfElementLocated(SETUP_PROGRESS_TEXT)).getText();
    Assert.assertEquals(str, "Setup Progress:");
}

From source file:com.grok.utils.TestUtilities.java

License:Open Source License

public static void waitClick(By locator, WebDriver driver, int value) {
    WebDriverWait wait = new WebDriverWait(driver, WAIT_TIME);
    wait.until(ExpectedConditions.presenceOfElementLocated(locator));
    JavascriptExecutor executor = (JavascriptExecutor) driver;
    executor.executeScript("arguments[0].click();", driver.findElement(locator));
}

From source file:com.grok.utils.TestUtilities.java

License:Open Source License

public static String waitGetText(By locator, WebDriver driver, int value) {
    WebDriverWait wait = new WebDriverWait(driver, WAIT_TIME);
    return wait.until(ExpectedConditions.presenceOfElementLocated(locator)).getText();
}

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

public boolean login() {
    openSite(LOGIN_URL);//from w w  w  .  j a  v  a2  s  .  c  om
    webDriver.findElement(By.id("login-email")).sendKeys(username);
    webDriver.findElement(By.id("login-password")).sendKeys(password);
    webDriver.findElement(By.className("login-form-submit")).findElement(By.tagName("button")).click();

    //        waitForSeconds(10);

    try {
        // if found then return true, otherwise return false
        (new WebDriverWait(this.webDriver, SPECIAL_TIMEOUT))
                .until(ExpectedConditions.presenceOfElementLocated(By.className("item-sign-out")));
        //            webDriver.findElement(By.className("item-sign-out")); 
    } catch (Exception ex) {
        System.out.println(ex);
        return false;
    }

    return true;
}

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

public void updateGumtreeModel(List<Gumtree> gumtrees) {
    List<Gumtree> gumtreesNeedToWrite = new ArrayList<>();
    int count = 0;
    int totalGumtreeLength = gumtrees.size();
    for (int i = 0; i < totalGumtreeLength; i++) {
        //            ad-attributes
        Gumtree gumtree = gumtrees.get(i);
        try {//from   w  w  w .  j a v  a2  s  .c o  m
            openSite(gumtree.getUrl());
            waitForPageToLoad();

            String content = (new WebDriverWait(this.webDriver, SPECIAL_TIMEOUT))
                    .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//meta[@name='WT.cg_s']")))
                    .getAttribute("content").toLowerCase();

            String type = content.contains("sale") ? "sale" : "rent";
            gumtree.setType(type);

            String saleRentId = "forsaleby_s-wrapper";
            if (type.equals("rent")) {
                saleRentId = "forrentby_s-wrapper";
            }

            String saleRentBy = (new WebDriverWait(this.webDriver, SPECIAL_TIMEOUT))
                    .until(ExpectedConditions.presenceOfElementLocated(
                            By.xpath("//div[@id='ad-attributes']/dl[contains(@id, '" + saleRentId + "')]/dd")))
                    .getText().trim();

            System.out.append("===Sale/Rent by: " + saleRentBy);

            if (!"owner".equalsIgnoreCase(saleRentBy)) {
                continue;
            }

            String name = (new WebDriverWait(this.webDriver, SPECIAL_TIMEOUT))
                    .until(ExpectedConditions.presenceOfElementLocated(
                            By.xpath("//div[@id='reply-form']//div[@class='reply-form-name']/a")))
                    .getText().trim();

            gumtree.setName(name);
            gumtreesNeedToWrite.add(gumtree);

            if ((i > 0 && (count % NUMBER_OF_LINE_TO_SERIALIZE) == 0) || (i == totalGumtreeLength - 1)) {
                writeToCsvFile(gumtreesNeedToWrite, fileName);
                gumtreesNeedToWrite.clear();
            }

        } catch (TimeoutException ex) {
            gumtree.setNotes("TIME_OUT");
            System.out.print(ex.getMessage());
        }
    }
}

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

private int getTotalPage(String url) {
    openSiteWithoutTimeout(url);// w ww .  j  a va 2 s .com
    String lastPageUrl = (new WebDriverWait(this.webDriver, 15))
            .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//a[@class='rs-paginator-btn last']")))
            .getAttribute("href");

    // http://www.gumtree.com.au/s-land-for-sale/page-109/c20031
    String findString = "/page-";
    int indexPage = lastPageUrl.indexOf(findString);
    int lastIndexOfSlash = lastPageUrl.lastIndexOf("/");
    String totalPageStr = lastPageUrl.substring(indexPage + findString.length(), lastIndexOfSlash);
    return Integer.parseInt(totalPageStr);
}

From source file:com.gwtplatform.carstore.cucumber.application.BasePage.java

License:Apache License

protected WebElement waitUntilPresenceOfElementLocated(By locator) {
    return webDriverWait().until(ExpectedConditions.presenceOfElementLocated(locator));
}