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:io.github.seleniumquery.utils.WebElementUtils.java

License:Apache License

public static boolean isSelectTag(WebElement element) {
    return "select".equals(element.getTagName());
}

From source file:io.github.seleniumquery.utils.WebElementUtils.java

License:Apache License

public static boolean isOptionTag(WebElement element) {
    return "option".equals(element.getTagName());
}

From source file:io.github.seleniumquery.utils.WebElementUtils.java

License:Apache License

public static boolean isInputTag(WebElement element) {
    return "input".equals(element.getTagName());
}

From source file:io.kahu.hawaii.cucumber.glue.html.HtmlSteps.java

License:Apache License

@When("^I fill in the fields?$")
public void I_fill_in_the_fields(DataTable data) throws Throwable {
    for (List<String> row : data.raw()) {
        String id = row.get(0);//from   w  w  w  . j  a  va  2  s.  co  m
        String value = row.get(1);
        WebElement element = findVisibleElementById(id);
        String tagName = element.getTagName();
        String type = element.getAttribute("type");
        if ("input".equalsIgnoreCase(tagName)) {
            if ("checkbox".equalsIgnoreCase(type)) {
                moveTo(element).click().perform();
            } else if ("radio".equalsIgnoreCase(type)) {
                moveTo(element).click().perform();
            } else {
                if (value != null) {
                    if (value.startsWith("date:")) {
                        String chronic = value.replaceFirst("date:", "").trim();
                        Calendar cal = parseChronic(chronic);
                        element.sendKeys(formatDate(cal));
                    } else if (value.startsWith("time:")) {
                        String chronic = value.replaceFirst("time:", "").trim();
                        Calendar cal = parseChronic(chronic);
                        element.sendKeys(formatTime(cal));
                    } else {
                        element.sendKeys(value);
                    }
                }
            }
        } else if ("select".equalsIgnoreCase(tagName)) {
            List<WebElement> options = element.findElements(By.tagName("option"));
            for (WebElement option : options) {
                if (option.getText().equals(value) || option.getAttribute("value").equals(value)) {
                    moveTo(option).click().perform();
                    break;
                }
            }
        } else if ("label".equalsIgnoreCase(tagName)) {
            moveTo(element).click().perform();
        } else {
            element.sendKeys(value);
        }
    }
}

From source file:io.selendroid.nativetests.NativeElementInteractionTest.java

License:Apache License

@Test
public void shouldoGetTagName() {
    openStartActivity();//from ww  w.  j  a  v a2  s  .  com
    WebElement inputField = driver().findElement(By.id("my_text_field"));
    Assert.assertEquals(inputField.getTagName(), "EditText");
}

From source file:io.selendroid.webviewdrivertests.WebElementFindingTest.java

License:Apache License

@Test
public void shouldGetBodyDOMElementViaJavascript() {
    openWebdriverTestPage(HtmlTestData.XHTML_TEST_PAGE);
    WebElement bodyByJS = (WebElement) driver().executeScript("return document.body;");
    Assert.assertEquals("body", bodyByJS.getTagName());
}

From source file:io.selendroid.webviewdrivertests.WebElementInteractionTest.java

License:Apache License

@Test
public void shouldGetTagNameOfElement() {
    openWebdriverTestPage(HtmlTestData.FORM_PAGE);
    WebElement button = driver().findElement(By.cssSelector("input[id='inputWithText']"));

    Assert.assertEquals(button.getTagName(), "input"); //< Specs "dictate" the tag names to be lower-case
}

From source file:io.spring.initializr.web.project.HomePage.java

License:Apache License

private Object getInputValue(WebElement input) {
    Object value = null;//w w  w.  j ava  2 s .  co  m
    String type = input.getAttribute("type");
    if ("select".equals(input.getTagName())) {
        Select select = new Select(input);
        if (select.isMultiple()) {
            value = select.getAllSelectedOptions().stream().map(this::getValue).collect(Collectors.toList());
        } else {
            value = getValue(select.getFirstSelectedOption());
        }
    } else if (Arrays.asList("checkbox", "radio").contains(type)) {
        if (input.isSelected()) {
            value = getValue(input);
        } else {
            if (Objects.equals(type, "checkbox")) {
                value = false;
            }
        }
    } else {
        value = getValue(input);
    }
    return value;
}

From source file:io.tourniquet.pageobjects.DynamicElementGroupInterceptor.java

License:Apache License

@Override
public Object intercept(final Object o, final Method method, final Object[] objects,
        final MethodProxy methodProxy) throws Throwable {

    if (Modifier.isAbstract(method.getModifiers())) {
        if (elements.containsKey(method)) {
            WebElement element = elements.get(method).get();
            if ("form".equals(element.getTagName())) {
                element.submit();//from  www  . jav a2  s .c  o  m
            } else if (objects.length == 1) {
                element.clear();
                element.sendKeys(objects[0].toString());
            } else if (objects.length == 0) {
                element.click();
            } else {
                throw new IllegalArgumentException("Method does not match web element " + element);
            }
            if (method.getReturnType().isAssignableFrom(o.getClass())) {
                return o;
            } else if (method.getReturnType().isAssignableFrom(WebElement.class)) {
                return element;
            }
            return null;

        } else {
            throw new NoSuchMethodException("Method " + method + " does not provide locator information");
        }

    }
    return methodProxy.invokeSuper(o, objects);
}

From source file:io.tourniquet.pageobjects.PageLoaderTest.java

License:Apache License

@Test
public void testAbstractPage_SubmitForm() throws Exception {
    //prepare/* www . j a  v a 2s  . c om*/
    new SeleniumContext(() -> webDriver).init();
    WebElement element = mock(WebElement.class);
    when(webDriver.findElement(By.id("someForm"))).thenReturn(element);
    when(element.isDisplayed()).thenReturn(true);
    when(element.getTagName()).thenReturn("form");

    //act
    AbstractPage page = PageLoader.loadPage(AbstractPage.class);

    //assert
    assertNotNull(page);
    page.submitForm();
    verify(element).submit();
    assertEquals("testpage", page.toString());
}