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.thoughtworks.selenium.webdriven.commands.GetValue.java

License:Apache License

@Override
protected String handleSeleneseCommand(WebDriver driver, String locator, String ignored) {
    WebElement element = finder.findElement(driver, locator);
    // Special-case handling for checkboxes and radio buttons: The Selenium API returns "on" for
    // checked checkboxes and radio buttons and off for unchecked ones. WebDriver will return "null" for
    // the "checked" attribute if the checkbox or the radio button is not-checked, "true" otherwise.
    if (element.getTagName().equals("input") && (element.getAttribute("type").equals("checkbox")
            || element.getAttribute("type").equals("radio"))) {
        if (element.getAttribute("checked") == null) {
            return "off";
        }//from   w  w  w.  j a  v  a  2  s  .  c  om
        return "on";
    }

    return element.getAttribute("value");
}

From source file:com.thoughtworks.selenium.webdriven.commands.IsEditable.java

License:Apache License

@Override
protected Boolean handleSeleneseCommand(WebDriver driver, String locator, String value) {
    WebElement element = finder.findElement(driver, locator);
    String tagName = element.getTagName().toLowerCase();
    boolean acceptableTagName = "input".equals(tagName) || "select".equals(tagName);
    String readonly = "";
    if ("input".equals(tagName)) {
        readonly = element.getAttribute("readonly");
        if (readonly == null || "false".equals(readonly)) {
            readonly = "";
        }/*ww w  . ja va  2s  .c om*/
    }

    return element.isEnabled() && acceptableTagName && "".equals(readonly);
}

From source file:com.thoughtworks.selenium.webdriven.commands.Type.java

License:Apache License

@Override
protected Void handleSeleneseCommand(WebDriver driver, String locator, String value) {
    alertOverride.replaceAlertMethod(driver);

    if (state.controlKeyDown || state.altKeyDown || state.metaKeyDown)
        throw new SeleniumException(
                "type not supported immediately after call to controlKeyDown() or altKeyDown() or metaKeyDown()");

    String valueToUse = state.shiftKeyDown ? value.toUpperCase() : value;

    WebElement element = finder.findElement(driver, locator);

    String tagName = element.getTagName();
    String elementType = element.getAttribute("type");
    if ("input".equals(tagName.toLowerCase()) && elementType != null
            && "file".equals(elementType.toLowerCase())) {
        log.warning("You should be using attachFile to set the value of a file input element");
        element.sendKeys(valueToUse);/* w w w  .j a v a 2 s. c  o  m*/
        return null;
    }

    if (!"input".equals(tagName.toLowerCase())) {
        if (driver instanceof JavascriptExecutor) {
            ((JavascriptExecutor) driver).executeScript("arguments[0].value = '';", element);
        }
        element.sendKeys(valueToUse);
        return null;
    }

    if (driver instanceof JavascriptExecutor) {
        js.executeScript(driver, type, element, valueToUse);
    } else {
        element.clear();
        element.sendKeys(valueToUse);
    }

    return null;
}

From source file:com.twiceagain.rservejavademo.extract.FTree.java

private void initFTree(WebDriver wd, WebElement we, FTree parent) {

    if (parent != null) {
        this.parent = parent;
        depth = parent.getDepth() + 1;//from   w w w.j  ava2s.c o  m

        path.addAll(parent.path);
        path.add(we.getTagName());

    }

    if (we != null) {
        tag = we.getTagName();
        visible = we.isDisplayed();
        if (isVisible()) {
            Dimension d = we.getSize();
            width = d.width;
            height = d.height;
            Point p = we.getLocation();
            x = p.x;
            y = p.y;
            area = getWidth() * getHeight();
            ratio = (getHeight() == 0) ? 0 : getWidth() / getHeight();
            text = we.getText();
        }
        attributes.putAll(BasicDriver.getAttributes(wd, we));
        String cl = attributes.get("class");
        if (cl != null) {
            classList.addAll(Arrays.asList(cl.split("\\s+")));
        }

        List<WebElement> lwe = we.findElements(By.xpath("./*"));
        for (WebElement w : lwe) {
            FTree cc = new FTree(wd, w, this);
            getChildren().add(cc);
        }
    }
}

From source file:com.vaadin.tests.components.grid.basicfeatures.client.GridEditorClientTest.java

License:Apache License

@Test
public void testFocusOnMouseOpen() {

    GridCellElement cell = getGridElement().getCell(4, 2);

    cell.doubleClick();//from w  w  w . j  av  a  2 s  . c o  m

    WebElement focused = getFocusedElement();

    assertEquals("", "input", focused.getTagName());
    assertEquals("", cell.getText(), focused.getAttribute("value"));
}

From source file:com.vaadin.tests.components.grid.basicfeatures.client.GridEditorClientTest.java

License:Apache License

@Test
public void testFocusOnKeyboardOpen() {

    GridCellElement cell = getGridElement().getCell(4, 2);

    cell.click();/*from www .j a va 2 s .c o  m*/
    new Actions(getDriver()).sendKeys(Keys.ENTER).perform();

    WebElement focused = getFocusedElement();

    assertEquals("", "input", focused.getTagName());
    assertEquals("", cell.getText(), focused.getAttribute("value"));
}

From source file:com.vaadin.tests.components.grid.basicfeatures.client.GridEditorClientTest.java

License:Apache License

@Test
public void testNoFocusOnProgrammaticOpen() {

    selectMenuPath(EDIT_ROW_5);//from  w  w w  . j a v a 2  s .c  o m

    WebElement focused = getFocusedElement();

    if (BrowserUtil.isIE(getDesiredCapabilities())) {
        assertEquals("Focus should be nowhere", null, focused);
    } else {
        // GWT menubar loses focus after clicking a menuitem
        assertEquals("Focus should be in body", "body", focused.getTagName());
    }
}

From source file:com.vaadin.tests.components.grid.basicfeatures.server.GridEditorTest.java

License:Apache License

@Test
public void testFocusOnProgrammaticOpenOnItemClick() {
    selectMenuPath("Component", "State", "EditorOpeningItemClickListener");

    GridCellElement cell = getGridElement().getCell(4, 2);

    cell.click();// w  ww. j a  v a 2s  .  c  om

    WebElement focused = getFocusedElement();

    assertEquals("", "input", focused.getTagName());
    assertEquals("", cell.getText(), focused.getAttribute("value"));
}

From source file:com.vaadin.v7.tests.components.grid.basicfeatures.escalator.EscalatorSpacerTest.java

License:Apache License

@Test
public void spacerOpenedInViewGetsFocus() {
    selectMenuPath(FEATURES, SPACERS, FOCUSABLE_UPDATER);
    selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX);
    tryToTabIntoFocusUpdaterElement();//from  w  w  w  . j  av  a 2  s  .c o  m
    WebElement focusedElement = getFocusedElement();
    assertEquals("input", focusedElement.getTagName());
}

From source file:com.watchrabbit.scanner.supervisor.service.FormAnalyzerServiceImpl.java

License:Apache License

@Override
public Form prepareStructure(WebElement formElement) throws InvalidFormStructureException {
    Form form = new Form.Builder().withForm(formElement).build();
    locateSendButton(formElement, form);
    List<WebElement> fieldElements = locateElements(formElement);
    for (int i = 0; i < fieldElements.size(); i++) {
        WebElement fieldElement = fieldElements.get(i);
        String label = extractLabel(formElement, i);

        ElementType elementType = ElementType.parse(fieldElement.getTagName().toUpperCase());
        FieldType fieldType = FieldType.parse(fieldElement.getAttribute("type").toUpperCase());

        String placeholder = fieldElement.getAttribute("placeholder");

        form.getFields().add(new Field.Builder().withElementType(elementType).withField(fieldElement)
                .withFieldType(fieldType).withLabel(label).withPlaceholder(placeholder).build());
    }//w  ww  .j  a  v a 2  s  .  c om
    return form;
}