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.asqatasun.tgol.test.scenario.AbstractWebDriverTestClass.java

License:Open Source License

protected String findAdminUserRowIndexLocation() {
    WebElement we = driver.findElement(By.xpath(USER_TABLE_BODY_XPATH_LOCATION));
    if (!StringUtils.equals(we.getTagName(), "tbody")) {
        throw new RuntimeException();
    }//from w w  w  .j av  a2  s.co m
    int rowIndex = 0;
    for (WebElement wec : we.findElements(By.tagName("tr"))) {
        rowIndex++;
        String userName = wec.findElement(By.className("col01")).getText();
        if (StringUtils.equals(userName, user)) {
            break;
        }
    }
    return String.valueOf(rowIndex);
}

From source file:org.auraframework.components.ui.dialogUITest.DialogUITest.java

License:Apache License

@ExcludeBrowsers({ BrowserType.ANDROID_PHONE, BrowserType.ANDROID_TABLET, BrowserType.IPAD,
        BrowserType.IPHONE })/*  www. j  a  v  a 2 s. c  o  m*/
public void testFocusElementsInDialog() throws MalformedURLException, URISyntaxException, InterruptedException {
    open(URL_MODAL_TABINDEX);
    WebDriver driver = getDriver();

    openDialogBox(driver);

    WebElement activeElement = getActiveElement();
    if (activeElement.getTagName().contains("button")) {
        // switch to the dialog if button still has focus
        auraUITestingUtil.pressTab(activeElement);
    }

    assertEquals("list item with tabindex=0 should be active element", "coffee",
            auraUITestingUtil.getEval(CLASSNAME));

    auraUITestingUtil.pressTab(getActiveElement());
    assertEquals("anchor element should be active", "anchor", auraUITestingUtil.getEval(CLASSNAME));
}

From source file:org.auraframework.components.ui.menu.MenuUITest.java

License:Apache License

public void testRemovingMenuDoesNotThrowJsError() throws MalformedURLException, URISyntaxException {
    open(MENUTEST_APP);//from   w w  w  .  jav a2 s  . c o  m
    WebDriver driver = this.getDriver();
    String uiMenuClassName = "clubMenu";
    String uiMenuLocalId = "uiMenu";
    WebElement menuLabel = driver.findElement(By.className(uiMenuClassName));
    assertTrue("UiMenu should be present on the page", menuLabel.isDisplayed());

    // For W-1540590
    assertEquals("ui:menu's wrapper element should be div", "div", menuLabel.getTagName());
    String uiMenu = auraUITestingUtil.getFindAtRootExpr(uiMenuLocalId);
    auraUITestingUtil.getEval("$A.unrender(" + uiMenu + ")");
    assertFalse("UiMenu should not be present after unrender", isElementPresent(By.className(uiMenuClassName)));
}

From source file:org.auraframework.integration.test.components.ui.menu.MenuUITest.java

License:Apache License

@Test
public void testRemovingMenuDoesNotThrowJsError() throws Exception {
    open(MENUTEST_APP);/*from w w  w . j  a v  a2s .c om*/
    WebDriver driver = this.getDriver();
    String uiMenuClassName = "clubMenu";
    String uiMenuLocalId = "uiMenu";
    WebElement menuLabel = driver.findElement(By.className(uiMenuClassName));
    assertTrue("UiMenu should be present on the page", menuLabel.isDisplayed());

    // For W-1540590
    assertEquals("ui:menu's wrapper element should be div", "div", menuLabel.getTagName());
    String uiMenu = getAuraUITestingUtil().getFindAtRootExpr(uiMenuLocalId);
    getAuraUITestingUtil().getEval("$A.unrender(" + uiMenu + ")");
    assertFalse("UiMenu should not be present after unrender", isElementPresent(By.className(uiMenuClassName)));
}

From source file:org.auraframework.integration.test.components.ui.modalOverlay.Panel2ModalOverlayUITest.java

License:Apache License

/**
 * Test panel when trapFocus is false/*from ww  w.  java 2  s .c  o m*/
 */
@Test
public void testPanelTabingWithTrapFocusFalse() throws Exception {
    String url = APP + "?" + PARAM_TRAP_FOCUS + "false";

    open(url);
    cycleThroughPanelInputElements(url, "modal", false);

    // check focus outside of panel
    getAuraUITestingUtil().waitUntil(new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver d) {
            WebElement activeElement = (WebElement) getAuraUITestingUtil().getEval(ACTIVE_ELEMENT);
            String tag = activeElement.getTagName();
            return "body".equals(tag);
        }
    }, "Focus should be on element outside of panel.");
}

From source file:org.cerberus.service.engine.impl.WebDriverService.java

License:Open Source License

@Override
public String getValueFromHTMLVisible(Session session, Identifier identifier) {
    String result = null;//  w  ww.  j  a v a 2 s. co  m
    AnswerItem answer = this.getSeleniumElement(session, identifier, true, false);
    if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {
        WebElement webElement = (WebElement) answer.getItem();
        if (webElement != null) {
            if (webElement.getTagName().equalsIgnoreCase("select")) {
                Select select = (Select) webElement;
                result = select.getFirstSelectedOption().getText();
            } else if (webElement.getTagName().equalsIgnoreCase("option")
                    || webElement.getTagName().equalsIgnoreCase("input")) {
                result = webElement.getAttribute("value");
            } else {
                result = webElement.getText();
            }
        }
    }

    return result;
}

From source file:org.cerberus.service.engine.impl.WebDriverService.java

License:Open Source License

@Override
public String getValueFromHTML(Session session, Identifier identifier) {
    AnswerItem answer = this.getSeleniumElement(session, identifier, false, false);
    String result = null;/*  ww  w . jav a 2s .  c o  m*/
    if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {
        WebElement webElement = (WebElement) answer.getItem();
        if (webElement != null) {
            if (webElement.getTagName().equalsIgnoreCase("select")) {
                if (webElement.getAttribute("disabled") == null
                        || webElement.getAttribute("disabled").isEmpty()) {
                    Select select = new Select(webElement);
                    result = select.getFirstSelectedOption().getText();
                } else {
                    result = webElement.getText();
                    //result = "Unable to retrieve, element disabled ?";
                }
            } else if (webElement.getTagName().equalsIgnoreCase("option")
                    || webElement.getTagName().equalsIgnoreCase("input")) {
                result = webElement.getAttribute("value");
            } else {
                result = webElement.getText();
            }
            /**
             * If return is empty, we search for hidden tags
             */
            if (StringUtil.isNullOrEmpty(result)) {
                String script = "return arguments[0].innerHTML";
                try {
                    result = (String) ((JavascriptExecutor) session.getDriver()).executeScript(script,
                            webElement);
                } catch (Exception e) {
                    MyLogger.log(WebDriverService.class.getName(), Level.DEBUG,
                            "getValueFromHTML locator : '" + identifier.getIdentifier() + "="
                                    + identifier.getLocator() + "', exception : " + e.getMessage());
                }
            }
        }
    } else if (answer.isCodeEquals(MessageEventEnum.ACTION_FAILED_WAIT_NO_SUCH_ELEMENT.getCode())) {
        throw new NoSuchElementException(identifier.getIdentifier() + "=" + identifier.getLocator());
    }
    return result;
}

From source file:org.cerberus.serviceEngine.impl.SeleniumService.java

License:Open Source License

@Override
public String getValueFromHTMLVisible(Selenium selenium, String locator) {
    WebElement webElement = this.getSeleniumElement(selenium, locator, true);
    String result;//  w  w  w.  j a va 2  s .co  m

    if (webElement.getTagName().equalsIgnoreCase("select")) {
        Select select = (Select) webElement;
        result = select.getFirstSelectedOption().getText();
    } else if (webElement.getTagName().equalsIgnoreCase("option")
            || webElement.getTagName().equalsIgnoreCase("input")) {
        result = webElement.getAttribute("value");
    } else {
        result = webElement.getText();
    }
    return result;
}

From source file:org.cerberus.serviceEngine.impl.SeleniumService.java

License:Open Source License

@Override
public String getValueFromHTML(Selenium selenium, String locator) {
    WebElement webElement = this.getSeleniumElement(selenium, locator, false);
    String result;/*from w w w .j  av  a 2 s  . c  o  m*/

    if (webElement.getTagName().equalsIgnoreCase("select")) {
        if (webElement.getAttribute("disabled") == null || webElement.getAttribute("disabled").isEmpty()) {
            Select select = (Select) webElement;
            result = select.getFirstSelectedOption().getText();
        } else {
            result = webElement.getText();
            //result = "Unable to retrieve, element disabled ?";
        }
    } else if (webElement.getTagName().equalsIgnoreCase("option")
            || webElement.getTagName().equalsIgnoreCase("input")) {
        result = webElement.getAttribute("value");
    } else {
        result = webElement.getText();
    }
    /**
     * If return is empty, we search for hidden tags
     */
    if (StringUtil.isNullOrEmpty(result)) {
        String script = "return arguments[0].innerHTML";
        result = (String) ((JavascriptExecutor) selenium.getDriver()).executeScript(script, webElement);
    }

    return result;
}

From source file:org.cerberus.serviceEngine.impl.WebDriverService.java

License:Open Source License

@Override
public String getValueFromHTMLVisible(Session session, String locator) {
    WebElement webElement = this.getSeleniumElement(session, locator, true, false);
    String result;/*from w  ww.jav a2s  .  c o m*/

    if (webElement.getTagName().equalsIgnoreCase("select")) {
        Select select = (Select) webElement;
        result = select.getFirstSelectedOption().getText();
    } else if (webElement.getTagName().equalsIgnoreCase("option")
            || webElement.getTagName().equalsIgnoreCase("input")) {
        result = webElement.getAttribute("value");
    } else {
        result = webElement.getText();
    }
    return result;
}