Example usage for org.openqa.selenium WebElement getTagName

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

Introduction

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

Prototype

String getTagName();

Source Link

Document

Get the tag name of this element.

Usage

From source file:com.seltaf.webelements.SelectList.java

License:Apache License

/**
 * Select standard select by attribute text, and select fake select with ul and li by attribute title.
 *
 * @param  text/*from  w w  w. j ava 2s  .com*/
 */
public void selectByText(final String text) {
    SeltafTestLogger.logWebStep(null, "make selection using text\"" + text + "\" on " + toHTML(), false);
    findElement();
    if (options == null) {
        driver.findElement(By.xpath("//li[text()='" + text + "']")).click();
        return;
    }

    for (WebElement option : options) {
        String selectedText = null;
        if (option.getTagName().equalsIgnoreCase("li")) {
            selectedText = option.getAttribute("title");
        } else {
            selectedText = option.getAttribute("text");
        }

        if (selectedText.equals(text)) {
            setSelected(option);
            break;
        }
    }
}

From source file:com.smash.revolance.ui.materials.mock.webdriver.PageTest.java

License:Open Source License

@Test
public void pageShouldHandleHtml() throws IOException {
    List<WebElement> elements = browser.findElements(By.xpath("//body//*"));
    assertThat(elements.size(), is(85));

    WebElement element = elements.get(0);

    Point location = element.getLocation();
    assertThat(location.getX(), is(255));
    assertThat(location.getY(), is(35));

    Dimension dimension = element.getSize();
    assertThat(dimension.getWidth(), is(879));
    assertThat(dimension.getHeight(), is(918));

    String tag = element.getTagName();
    assertThat(tag, is("div"));

    String txt = element.getText();
    assertThat(txt, is(nullValue()));//from w  ww .ja v  a  2s. c o  m

    String cssClass = element.getAttribute("class");
    assertThat(cssClass, is("page"));
}

From source file:com.smash.revolance.ui.model.element.api.Element.java

License:Open Source License

public Element(Page page, WebElement element) {
    this();//from   ww  w .  j a  v  a2 s  .  c o  m
    setPage(page);
    setTag(element.getTagName());
    setDim(element.getSize());
    setPos(element.getLocation());
    setClz(element.getAttribute("class"));
    setId(element.getAttribute("id"));
}

From source file:com.smash.revolance.ui.model.element.api.Element.java

License:Open Source License

public static Class<? extends Element> getImplementation(WebElement element) {
    String tag = element.getTagName();
    if (tag == null) {
        tag = "";
    }//from   w ww.j  av  a 2s. c  o  m
    String type = element.getAttribute("type");
    if (type == null) {
        type = "";
    }
    String txt = element.getText();
    if (txt == null) {
        txt = "";
    }
    if (isALink(tag, txt)) {
        return Link.class;
    } else if (isAButton(tag, type)) {
        return Button.class;
    } else if (isAnInput(tag, type)) {
        return Input.class;
    } else if (isAData(tag, txt)) {
        return Data.class;
    } else if (isAnImage(element, tag)) {
        return Image.class;
    } else {
        return null;
    }
}

From source file:com.smash.revolance.ui.model.element.api.Image.java

License:Open Source License

public Image(Page page, WebElement element) {
    super(page, element);
    setText("");//from ww  w  .  j a v  a  2  s . c om
    setImplementation("Image");
    setBackground(getBg(element.getTagName(), element));
    setAlt(element.getAttribute("alt"));
}

From source file:com.stratio.qa.conditions.TextFieldCondition.java

License:Apache License

public TextFieldCondition() {
    cond = new Condition<WebElement>("textField") {
        @Override//from  w  w w .ja  va 2 s.  c o m
        public boolean matches(WebElement value) {
            switch (value.getTagName()) {
            case "input":
                return ("text".equals(value.getAttribute("type"))
                        || "input".equals(value.getAttribute("type")));
            case "textarea":
                return ("text".equals(value.getAttribute("type"))
                        || "textarea".equals(value.getAttribute("type")));
            default:
                return false;
            }
        }
    };
}

From source file:com.sugarcrm.candybean.examples.mobile.AppiumIosTest.java

License:Open Source License

@Test
public void testBasicTagName() throws Exception {
    WebElement text = driver.findElement(By.xpath("//textfield[1]"));
    assertEquals(text.getTagName(), "UIATextField");
}

From source file:com.technophobia.webdriver.substeps.impl.AssertionWebDriverSubStepImplementations.java

License:Open Source License

/**
 * Utility method to check that an element is of a particular tag and type
 * // w  ww  .j  a  v a 2  s.c om
 * @param elem the element
 *
 * @param tag the expected tag
 * @param type the expected type attribute
 */
public static void assertElementIs(final WebElement elem, final String tag, final String type) {

    Assert.assertNotNull("expecting an element", elem);
    Assert.assertTrue("unexpected tag",
            elem.getTagName() != null && elem.getTagName().compareToIgnoreCase(tag) == 0);

    if (type != null) {
        Assert.assertTrue("unexpected type",
                elem.getAttribute("type") != null && elem.getAttribute("type").compareToIgnoreCase(type) == 0);
    }
}

From source file:com.technophobia.webdriver.substeps.impl.TableSubStepImplementations.java

License:Open Source License

/**
 * Find a row in a table where columns exist that contain the specified
 * text. Not all columns of the table need to specified, however the order
 * is important. Finding multiple matching results will result in an error.
 * //w  w  w  . j  a va 2  s.  c  om
 * Once the row has been located, other FindInRow methods can be used that
 * may in turn refer to and set the 'Current Element', this method does not
 * set the current element for that reason.
 * 
 * @example FindTableRowWithColumnsThatContainText
 *          ["My Name","Where it all began...","December 19 2012"]
 * @section Table
 * 
 * @param columnText
 *            A comma delimitted list of column values, each column can be
 *            double quoted
 */
@Step("FindTableRowWithColumnsThatContainText \\[(.*)\\]")
public void findRowInTableWithText(final String columnText) {

    final WebElement currentElement = webDriverContext().getCurrentElement();

    Assert.assertThat("expecting the current element to be a table", currentElement.getTagName(),
            equalToIgnoringCase("table"));

    final String[] columnValues = columnText.split(",");
    final List<String> columnValList = new ArrayList<String>();
    for (final String s : columnValues) {
        columnValList.add(s.replaceAll("\"", "").trim());
    }

    final List<WebElement> tableRows = currentElement.findElements(By.tagName("tr"));

    List<WebElement> matchingRows = null;

    // TODO - refactor this into WebDriver Bys ..?

    // go through all rows
    for (final WebElement row : tableRows) {

        // for each row
        final List<WebElement> tableCells = row.findElements(By.tagName("td"));

        int lookingForIdx = 0;

        boolean found = false;
        // do we have a match ?
        for (final WebElement td : tableCells) {

            if (td.getText().contains(columnValList.get(lookingForIdx))) {

                lookingForIdx++;
                if (lookingForIdx >= columnValList.size()) {
                    // found em all
                    found = true;
                    break;
                }
            }
        }

        if (found) {
            if (matchingRows == null) {
                matchingRows = new ArrayList<WebElement>();
            }
            matchingRows.add(row);
        }

    }

    Assert.assertNotNull("Didn't find any rows with values: [" + columnText + "]", matchingRows);

    Assert.assertThat("Found too many rows that match values: [" + columnText + "]", matchingRows.size(),
            is(1));

    webDriverContext().stashElement(TABLE_ROW_KEY, matchingRows.get(0));
}

From source file:com.technophobia.webdriver.substeps.impl.TableSubStepImplementations.java

License:Open Source License

private WebElement findElementInRowBy(final By by) {

    webDriverContext().setCurrentElement(null);

    final WebElement row = webDriverContext().getElementFromStash(TABLE_ROW_KEY);

    Assert.assertThat("expecting the current element to be a table", row.getTagName(),
            equalToIgnoringCase("tr"));

    // go through all td's in this row, collect all elements that match the
    // by//  w w w.j a v a2  s  .  com

    final List<WebElement> tableCells = row.findElements(By.tagName("td"));

    List<WebElement> matchingElements = null;

    for (final WebElement e : tableCells) {

        final List<WebElement> foundElements = e.findElements(by);
        if (foundElements != null && !foundElements.isEmpty()) {

            if (matchingElements == null) {
                matchingElements = new ArrayList<WebElement>();
            }
            matchingElements.addAll(foundElements);
        }
    }

    Assert.assertNotNull("expecting to have found some elements", matchingElements);
    Assert.assertThat("Found too many elements in the row", matchingElements.size(), is(1));

    final WebElement current = matchingElements.get(0);
    webDriverContext().setCurrentElement(current);

    return current;
}