Example usage for org.openqa.selenium WebElement getAttribute

List of usage examples for org.openqa.selenium WebElement getAttribute

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement getAttribute.

Prototype

String getAttribute(String name);

Source Link

Document

Get the value of the given attribute of the element.

Usage

From source file:be.rubus.web.jerry.validation.MaxSizeTest.java

License:Apache License

@Test
@RunAsClient//w w  w .ja va  2  s.  co m
public void testMaxLength() throws Exception {
    driver.get(new URL(contextPath, "maxSize.xhtml").toString());

    WebElement element = driver.findElement(By.id("test:default"));
    assertThat(element.getAttribute("maxlength")).isNull();

    element = driver.findElement(By.id("test:value"));
    assertThat(element.getAttribute("maxlength")).isNull();

    element = driver.findElement(By.id("test:standard"));
    assertThat(element.getAttribute("maxlength")).isEqualTo("5");

    element = driver.findElement(By.id("test:maxLength"));
    assertThat(element.getAttribute("maxlength")).isEqualTo("5");

    element = driver.findElement(By.id("test:special"));
    assertThat(element.getAttribute("maxlength")).isEqualTo("7");

}

From source file:be.rubus.web.jerry.validation.MaxSizeTest.java

License:Apache License

@Test
@RunAsClient/*w  w  w .  j  a va2 s  . c o m*/
public void testMaxLength_TextArea() throws Exception {
    driver.get(new URL(contextPath, "maxSize_TextArea.xhtml").toString());

    WebElement element = driver.findElement(By.id("frm:description"));

    WebElement remaining = driver.findElement(By.id("frm:remaining"));
    assertThat(remaining.getText()).contains("10");

    element.sendKeys("abcde");
    assertThat(remaining.getText()).contains("5");

    element.sendKeys("abcdefghijk");
    assertThat(remaining.getText()).contains("0");

    assertThat(element.getAttribute("value")).isEqualTo("abcdeabcde");

}

From source file:be.rubus.web.testing.AbstractWidget.java

License:Apache License

public String getContentInAnyCase(WebElement element) {
    String result = element.getText();
    if (result == null || result.length() == 0) {
        result = element.getAttribute("textContent");
        if (result == null || result.length() == 0) {
            result = element.getAttribute("innerText");
        }//from   w  w w. j a  v  a 2  s. com
    }
    return result;
}

From source file:be.rubus.web.testing.CommonElementCode.java

License:Apache License

protected String getStyleClasses(WebElement element) {
    return element.getAttribute("class");
}

From source file:be.rubus.web.testing.CommonElementCode.java

License:Apache License

protected String getId(WebElement element) {
    return element.getAttribute("id");
}

From source file:be.rubus.web.testing.CommonElementCode.java

License:Apache License

protected String getAttribute(WebElement someElement, String attributeName) {
    return someElement.getAttribute(attributeName);
}

From source file:bi.meteorite.pages.SaikuTable.java

License:Apache License

private boolean hasMatchingCellValuesIn(WebElement firstRow, List<String> headings) {
    String html = firstRow.getAttribute("innerHTML");
    List<WebElement> cells = firstRow.findElements(By.xpath("//td | //th"));
    for (int cellIndex = 0; cellIndex < headings.size(); cellIndex++) {
        if ((cells.size() < cellIndex) || (!cells.get(cellIndex).getText().equals(headings.get(cellIndex)))) {
            return false;
        }/*from  ww  w . j a v a  2s .c o m*/
    }
    return true;
}

From source file:botski.example.PinterestExample.java

License:Apache License

public void run() {
    try {//from  w  w w  . j a  v a  2 s  . co m
        // Set your Proxy here
        useProxy("123.123.123.123", 8080);

        // Default to Firefox, but could use Chrome
        initializeFirefox();

        // Login and goto the homepage
        pinterestLogin("email@address.com", "password");

        // Search the DOM to find all visible Like buttons
        List<WebElement> list = browser.findElements(By.className("likebutton"));
        System.out.println("Found " + list.size() + " 'Like' buttons!");

        // Randomly 'Like' ~ 10% of them
        int count = 0;
        for (WebElement element : list) {
            if (Math.random() <= 0.10) // roughly 10%
            {
                // Click the 'Like' button using Javascript
                javascript.executeScript("arguments[0].click();", element);
                System.out.println("   ... Liked pin " + element.getAttribute("data-id"));
                count++;
            }
        }
        System.out.println("Liked " + count + " pins!");

        // Sleep for 5 seconds then quit
        sleep(5000);
        browser.quit();
    } catch (Exception e) {
        System.err.println("Something has gone horribly wrong!");
        e.printStackTrace();
    }
}

From source file:br.eti.kinoshita.selenium.util.Utils.java

License:Open Source License

/**
 * Click on a WebElement as many times are necessary checking 
 * if some attribute value has changed//from  w ww  .  ja v a2  s  .  c o  m
 * 
 * @param elementToClick
 * @param attributeType
 * @param attributeValue
 */
public static void clickAndWaitForElementAttributeChange(WebElement elementToClick, String attributeType,
        String attributeValue) {
    for (int i = 0; i < 10; ++i) {
        elementToClick.click();
        String elementAttribute = elementToClick.getAttribute(attributeType);

        if (StringUtils.isNotBlank(elementAttribute) && elementAttribute.contains(attributeValue)) {
            sleep(750L);
        } else {
            break;
        }
    }
}

From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.ui.primefaces.PrimefacesGrid.java

License:Open Source License

@Override
public String findTextInTable(Element element, String l, String c) {
    String xpathTabela = preparaXPath(element, l, c);
    WebElement myElement = (WebElement) ((WebDriver) runner.getDriver()).findElement(By.xpath(xpathTabela));
    String str = "";
    try {//from w w  w .  j a v a 2  s .c o  m
        str = myElement.getText();
    } catch (Exception ex) {
    }
    if (str == null || str.isEmpty()) {
        xpathTabela = xpathTabela.concat("//input[@type='text']");
        myElement = ((WebDriver) runner.getDriver()).findElement(By.xpath(xpathTabela));
        str = myElement.getAttribute("value");
    }
    return str;
}