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:org.webtestingexplorer.state.VisibleElementsState.java

License:Open Source License

/**
 * Get information of a WebElement./* w w w.  jav  a 2 s . c om*/
 */
private Map<WebElementIdentifier, Map<String, String>> collectProperties(WebDriverWrapper driver,
        List<WebElementWithIdentifier> elements) {
    Map<WebElementIdentifier, Map<String, String>> allProperties = new HashMap<WebElementIdentifier, Map<String, String>>();

    for (WebElementWithIdentifier elementWithId : elements) {
        // Get all properties
        WebElement e = elementWithId.getElement();
        Map<String, String> properties = new HashMap<String, String>();
        String value = e.getTagName();
        if (value != null) {
            properties.put(TAG_NAME, value);
        }

        value = e.getText();
        if (value != null) {
            properties.put(VALUE, value);
        }

        properties.put(ENABLED, Boolean.toString(e.isEnabled()));
        properties.put(SELECTED, Boolean.toString(e.isSelected()));

        for (String attribute : ELEMENT_ATTRIBUTES) {
            String attributeValue = e.getAttribute(attribute);
            if (attributeValue != null) {
                properties.put(attribute, attributeValue);
            }
        }

        allProperties.put(elementWithId.getIdentifier(), properties);
    }

    return allProperties;
}

From source file:org.wso2.mb.integration.common.utils.ui.pages.main.QueueSubscriptionsPage.java

License:Open Source License

/**
 * Gets the number of queue subscriptions.
 *
 * @return the number of subscriptions./*from ww w .ja  va  2 s.  co m*/
 */
public int getSubscriptionCount() {
    int numberOfSubscribers = 0;

    WebElement subscriptionTable = driver.findElement(
            By.xpath(UIElementMapper.getInstance().getElement("mb.subscriptions.queue.table.xpath")));
    // Checks whether the table exists.
    if ("table".equals(subscriptionTable.getTagName())) {
        numberOfSubscribers = subscriptionTable.findElement(By.tagName("tbody")).findElements(By.tagName("tr"))
                .size();
    }
    if (numberOfSubscribers == 0) {
        log.warn("Queue Subscriptions table does not exists.");
    }
    return numberOfSubscribers;
}

From source file:org.wso2.mb.integration.common.utils.ui.pages.main.TopicSubscriptionsPage.java

License:Open Source License

/**
 * Gets the number of temporary active subscriptions.
 *
 * @return The number of subscriptions.//from  ww w  .j a  v a  2 s. c o m
 */
public int getNonDurableSubscriptionsCount() {
    int numberOfSubscribers = 0;
    List<WebElement> tempNonDurableActiveTables = driver.findElements(By.xpath(
            UIElementMapper.getInstance().getElement("mb.subscriptions.topics.page.temporary.table.xpath")));
    // Checks whether the table exists.
    if (0 < tempNonDurableActiveTables.size()) {
        for (WebElement tempNonDurableActiveTable : tempNonDurableActiveTables) {
            if ("table".equals(tempNonDurableActiveTable.getTagName())) {
                numberOfSubscribers = tempNonDurableActiveTable.findElement(By.tagName("tbody"))
                        .findElements(By.tagName("tr")).size();
            }
        }

    }

    if (numberOfSubscribers == 0) {
        log.warn("Durable Active Subscriptions table does not exists.");
    }
    return numberOfSubscribers;
}

From source file:org.xframium.page.element.SeleniumElement.java

License:Open Source License

@Override
protected String _getValue() {
    long startTime = System.currentTimeMillis();
    WebElement currentElement = getElement();

    String returnValue = null;//from   w w w. j  a  va 2s.co  m
    switch (currentElement.getTagName().toUpperCase()) {
    case "IMG":
        returnValue = currentElement.getAttribute("src");

    case "INPUT":
        returnValue = currentElement.getAttribute("value");

    default:
        returnValue = currentElement.getText();
    }

    PageManager.instance().addExecutionLog(getExecutionId(), getDeviceName(), getPageName(), getElementName(),
            "get", System.currentTimeMillis(), System.currentTimeMillis() - startTime, StepStatus.SUCCESS,
            getKey(), null, 0, "", currentElement instanceof CachedElement, new String[] { returnValue });
    return returnValue;
}

From source file:org.xframium.page.element.SeleniumElement.java

License:Open Source License

@Override
protected void _setValue(String currentValue, SetMethod setMethod) {
    WebElement webElement = getElement();

    if (webElement.getTagName().equalsIgnoreCase("select")) {
        if (log.isInfoEnabled())
            log.info(Thread.currentThread().getName() + ": Selecting element value from [" + getKey() + "] as "
                    + currentValue);/*ww w  .  jav a2s. c  om*/

        Select selectElement = new Select(webElement);
        if (selectElement.isMultiple())
            selectElement.deselectAll();
        try {
            selectElement.selectByVisibleText(currentValue);
        } catch (Exception e) {
            selectElement.selectByValue(currentValue);
        }
    } else {
        switch (setMethod) {
        case DEFAULT:
            if (log.isInfoEnabled())
                log.info(Thread.currentThread().getName() + ": Setting element [" + getKey() + "] to "
                        + currentValue);

            MorelandWebElement x = (MorelandWebElement) webElement;
            if (x.getWebElement() instanceof IOSElement)
                ((IOSElement) x.getWebElement()).setValue(currentValue);
            else {
                webElement.clear();
                webElement.sendKeys(currentValue);
            }
            break;

        case SINGLE:
            if (log.isInfoEnabled())
                log.info(Thread.currentThread().getName() + ": Setting element [" + getKey() + "] to "
                        + currentValue + " using individual send keys");

            webElement.sendKeys(currentValue);

        }
    }

}

From source file:org.xmlium.test.web.commons.xml.XMLTestSteps.java

License:LGPL

protected void checkStoreValue(Element e, WebElement element) {
    logger.debug(e);//  www .jav a2 s . c  o  m
    if (e.getStoreValue() != null && e.getStoreValue().getKey() != null) {

        String strValue = element.getAttribute("value");
        if (strValue == null || strValue.isEmpty()) {
            if (!element.getTagName().equalsIgnoreCase("input")) {
                strValue = element.getText();
            }
        }
        if (strValue == null || strValue.isEmpty()) {
            throw new RuntimeException(e.toString() + "\n value attribute is empty or null!");
        }
        Boolean unformat = false;
        if (e.getFinds().getFind() != null) {
            unformat = e.getFinds().getFind().isUnformat();
        } else {
            if (e.getFinds().getWaitFor() != null) {
                unformat = e.getFinds().getWaitFor().isUnformat();
            }
        }
        elementValuesMap.put(unformatValue(unformat, e.getStoreValue().getKey()), strValue);
    } else if (e.getStoreValue() != null && e.getStoreValue().getKey() == null) {
        throw new RuntimeException(e.toString() + "\n key==null!");
    }
}

From source file:org.xwiki.appwithinminutes.test.po.StaticListClassFieldEditPane.java

License:Open Source License

/**
 * @return the type of HTML input used to preview the list; possible returned values are specified by
 *         {@link #getDisplayTypeSelect()}
 *///from w  ww .ja v  a  2 s  . com
public String getPreviewInputType() {
    By xpath = By.xpath(".//*[local-name() = 'select' or (local-name() = 'input' and not(@type = 'hidden'))]");
    List<WebElement> inputs = getUtil().findElementsWithoutWaiting(getDriver(), defaultValueContainer, xpath);
    if (inputs.size() > 0) {
        WebElement input = inputs.get(0);
        return "select".equalsIgnoreCase(input.getTagName()) ? "select"
                : input.getAttribute("type").toLowerCase();
    }
    return null;
}

From source file:org.xwiki.test.ui.framework.elements.FormElement.java

License:Open Source License

public void setFieldValue(WebElement fieldElement, String value) {
    if ("checkbox".equals(fieldElement.getAttribute("type"))) {
        setCheckBox(fieldElement, value.equals("true"));
    } else if ("select".equals(fieldElement.getTagName())) {
        Select select = new Select(fieldElement);
        select.selectByValue(value);/*from  w  ww  .  java2 s .  co  m*/
    } else {
        fieldElement.clear();
        fieldElement.sendKeys(value);
    }
}

From source file:org.xwiki.test.ui.framework.elements.TableElement.java

License:Open Source License

public TableElement(WebElement table) {
    super();//from  w  w  w  .  java2s. co  m
    if (!table.getTagName().toLowerCase().equals("table")) {
        throw new WebDriverException("You can only create a TableElement using a <table> web element,"
                + "you passed a <" + table.getTagName() + "> element");
    }
    if (!table.findElements(By.tagName("tbody")).isEmpty()) {
        this.table = table.findElements(By.tagName("tbody")).get(0);
    } else {
        this.table = table;
    }
}

From source file:org.xwiki.test.ui.po.LiveTableElement.java

License:Open Source License

public void filterColumn(String inputId, String filterValue) {
    // Make extra sure Selenium can't go quicker than the live table status by forcing it before filtering.
    executeJavascript("return $('" + livetableId + "-ajax-loader').removeClassName('hidden')");

    WebElement element = getDriver().findElement(By.id(inputId));
    if ("select".equals(element.getTagName())) {
        new Select(element).selectByVisibleText(filterValue);
    } else {// w  w w .  j av  a2 s.co  m
        element.clear();
        element.sendKeys(filterValue);
    }
    waitUntilReady();
}