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:io.github.bonigarcia.wdm.test.ChromeTest.java

License:Apache License

@Test
public void test() {
    // 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

    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:io.github.bonigarcia.wdm.test.ManagerTest.java

License:Open Source License

public void browseWikipedia() {
    WebDriverWait wait = new WebDriverWait(driver, TIMEOUT);
    driver.get("http://en.wikipedia.org/wiki/Main_Page");

    By searchInput = By.id("searchInput");
    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 or simply software"));
}

From source file:io.github.bonigarcia.wdm.test.PerformanceChromeTest.java

License:Apache License

private void singleTestExcution(WebDriver driver) {
    WebDriverWait wait = new WebDriverWait(driver, 30); // 30 seconds of timeout
    driver.get("https://en.wikipedia.org/wiki/Main_Page"); // navigate to Wikipedia

    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:io.github.bonigarcia.wdm.test.PerformancePhantomJsTest.java

License:Apache License

private void singleTestExcution(WebDriver driver) {
    WebDriverWait wait = new WebDriverWait(driver, 30); // 30 seconds of timeout
    driver.get("https://en.wikipedia.org/wiki/Main_Page"); // navigate to Wikipedia

    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:io.github.bonigarcia.wdm.test.RemoteTest.java

License:Apache License

@Test
public void test() {
    WebDriverWait wait = new WebDriverWait(driver, 30);
    driver.get("https://en.wikipedia.org/wiki/Main_Page");
    By searchInput = By.id("searchInput");
    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"));
}

From source file:io.openvidu.test.OpenViduClientBrowserTest.java

License:Apache License

public WebElement findElement(String label, Browser browser, String id) {
    try {/* w w w  .  j  a  v a  2s.c o  m*/
        return new WebDriverWait(browser.getWebDriver(), testTimeout, POLLING_LATENCY)
                .until(ExpectedConditions.presenceOfElementLocated(By.id(id)));
    } catch (TimeoutException e) {
        log.warn("Timeout when waiting for element {} to exist in browser {}", id, label);
        int originalTimeout = 60;
        try {
            originalTimeout = browser.getTimeout();
            log.debug("Original browser timeout (s): {}, set to 10", originalTimeout);
            browser.setTimeout(10);
            browser.changeTimeout(10);
            WebElement elem = browser.getWebDriver().findElement(By.id(id));
            log.info("Additional findElement call was able to locate {} in browser {}", id, label);
            return elem;
        } catch (NoSuchElementException e1) {
            log.debug("Additional findElement call couldn't locate {} in browser {} ({})", id, label,
                    e1.getMessage());
            throw new NoSuchElementException("Element with id='" + id + "' not found after " + testTimeout
                    + " seconds in browser " + label);
        } finally {
            browser.setTimeout(originalTimeout);
            browser.changeTimeout(originalTimeout);
        }
    }
}

From source file:io.selendroid.client.waiter.TestWaiter.java

License:Apache License

public static WebElement waitForElement(By by, int timeout, WebDriver driver) {
    WebDriverWait wait = new WebDriverWait(driver, timeout);
    WebElement element = wait.until(ExpectedConditions.presenceOfElementLocated(by));

    return element;
}

From source file:io.selendroid.nativetests.NativeElementFindingTest.java

License:Apache License

@Test()
public void shouldNotFindElementByIdFromPreviousActivity() {
    openStartActivity();/* w  w  w .java2  s  . c o  m*/
    driver().findElement(By.id("startUserRegistration")).click();
    new WebDriverWait(driver(), 5).until(ExpectedConditions.presenceOfElementLocated(By.id("inputUsername")));

    try {
        driver().findElement(By.id("buttonStartWebview"));
        Assert.fail("The element from previous screen should not be found.");
    } catch (NoSuchElementException e) {
        // // this element is located on previous activity and should not be found
    }
}

From source file:io.selendroid.nativetests.NativeElementFindingTest.java

License:Apache License

@Test()
public void shouldThrowStaleElementReferenceError() {
    openStartActivity();/*  w  w  w  . jav  a2s . c  o  m*/
    WebElement textfield = driver().findElement(By.id("my_text_field"));
    Assert.assertNotNull("textfield should be found.", textfield);
    driver().findElement(By.id("startUserRegistration")).click();
    new WebDriverWait(driver(), 5).until(ExpectedConditions.presenceOfElementLocated(By.id("inputUsername")));

    try {
        textfield.sendKeys("Hello");
        Assert.fail("The element from previous screen should not be found.");
    } catch (StaleElementReferenceException e) {
        // // this element is located on previous activity and should not be found
    }
}

From source file:io.selendroid.nativetests.NativeElementInteractionTest.java

License:Apache License

@Test
public void shouldScrollAndEnterText() {
    openStartActivity();//ww  w  .  j  a  va 2s.  co m

    driver().findElement(By.id("startUserRegistration")).click();
    new WebDriverWait(driver(), 5).until(ExpectedConditions.presenceOfElementLocated(By.id("inputUsername")));
    WebElement acceptAddsCheckbox = driver().findElement(By.id("input_adds"));
    if (acceptAddsCheckbox.isSelected()) {
        acceptAddsCheckbox.click();
        Assert.assertEquals(false, acceptAddsCheckbox.isSelected());
    } else {
        acceptAddsCheckbox.click();
        Assert.assertEquals(true, acceptAddsCheckbox.isSelected());
    }
}