Example usage for org.openqa.selenium WebDriver findElement

List of usage examples for org.openqa.selenium WebDriver findElement

Introduction

In this page you can find the example usage for org.openqa.selenium WebDriver findElement.

Prototype

@Override
WebElement findElement(By by);

Source Link

Document

Find the first WebElement using the given method.

Usage

From source file:at.ac.tuwien.big.testsuite.impl.selenium.BaseSeleniumTest.java

License:Apache License

protected static String textById(WebDriver driver, String id) {
    try {//w  ww.  jav a  2  s  .  c om
        return driver.findElement(By.id(id)).getText().trim();
    } catch (NoSuchElementException ex) {
        return null;
    }
}

From source file:at.ac.tuwien.big.testsuite.impl.selenium.BaseSeleniumTest.java

License:Apache License

protected static WebElement getParentElement(WebDriver driver, By by) {
    try {//w  w w  .  ja v  a  2  s.co  m
        WebElement element = driver.findElement(by);
        return element.findElement(By.xpath(".."));
    } catch (NoSuchElementException ex) {
        return null;
    }
}

From source file:at.ac.tuwien.big.testsuite.impl.selenium.BaseSeleniumTest.java

License:Apache License

protected static boolean exists(WebDriver driver, By by) {
    try {//from ww  w. j  a v  a2 s . c  o  m
        driver.findElement(by);
        return true;
    } catch (NoSuchElementException e) {
        return false;
    }
}

From source file:at.ac.tuwien.big.testsuite.impl.selenium.BaseSeleniumTest.java

License:Apache License

protected static void clickNonAjax(WebDriver driver, By by) {
    driver.findElement(by).click();
    wait(200);
}

From source file:at.ac.tuwien.big.testsuite.impl.selenium.BaseSeleniumTest.java

License:Apache License

protected static void writeText(WebDriver driver, String id, String text) {
    final WebElement elem = driver.findElement(By.name(id));
    elem.clear();/*from  w ww  . ja  v a 2  s  .com*/
    elem.sendKeys(text);
}

From source file:at.ac.tuwien.big.testsuite.impl.selenium.BaseSeleniumTest.java

License:Apache License

protected static boolean isElementDisplayed(WebDriver driver, By by) {
    return driver.findElement(by).isDisplayed();
}

From source file:at.ac.tuwien.big.testsuite.impl.selenium.BaseSeleniumTest.java

License:Apache License

protected static void clickAjax(WebDriver driver, By by) {
    driver.findElement(by).click();
    waitForJQuery(driver);
}

From source file:at.ac.tuwien.big.testsuite.impl.selenium.LoginTest.java

License:Apache License

public void doLogin(WebDriver driver, String username, String password) {
    checkThat("Login form element 'name' with id 'login:form:name' does not exist", true,
            is(exists(driver, By.id("login:form:name"))));
    checkThat("Login form element 'password' with id 'login:form:password' does not exist", true,
            is(exists(driver, By.id("login:form:password"))));
    checkThat("Login form element 'submit' with id 'login:form:submit' does not exist", true,
            is(exists(driver, By.id("login:form:submit"))));

    driver.findElement(By.id("login:form:name")).sendKeys(username);
    driver.findElement(By.id("login:form:password")).sendKeys(password);
    driver.findElement(By.id("login:form:submit")).click();
    wait(200);//from  ww w.  j  av  a  2  s .co  m
    waitForJQuery(driver);
}

From source file:at.ac.tuwien.big.testsuite.impl.selenium.TableTest.java

License:Apache License

private Integer getDiceValue(WebDriver driver) {
    String src = null;//from   w w  w  . ja  va  2  s .  c  o  m

    if (exists(driver, By.id(diceFormPrefix + "diceImage"))) {
        src = driver.findElement(By.id(diceFormPrefix + "diceImage")).getAttribute("src");
    } else if (exists(driver, By.id(diceFormPrefix + "dice"))) {
        WebElement diceElement = driver.findElement(By.id(diceFormPrefix + "dice"));
        src = diceElement.getAttribute("src");

        if (src == null) {
            List<WebElement> imgElems = diceElement.findElements(By.xpath(".//img"));

            if (!imgElems.isEmpty()) {
                diceElement = imgElems.get(0);
                src = diceElement.getAttribute("src");
            }
        }
    }

    if (src == null) {
        assertFalse(TestsuiteConstants.KNOWN_ERROR_PREFIX + " Could not retrieve dice value", true);
    }

    Matcher matcher = DICE_VALUE_PATTERN.matcher(src);

    if (!matcher.matches()) {
        assertFalse(TestsuiteConstants.KNOWN_ERROR_PREFIX + " Could not retrieve dice value", true);
    }

    return Integer.parseInt(matcher.group(1));
}

From source file:at.ac.tuwien.big.testsuite.impl.selenium.TableTest.java

License:Apache License

private Boolean isOily(WebDriver driver, int roadId) {
    WebElement road = driver.findElement(By.id("road_" + roadId));
    return road == null ? null : road.getAttribute("class").contains("oil_road");
}