官术网_书友最值得收藏!

The getTagName() method

The getTagName method can be called from all the WebElements. This will return the HTML tag name of the WebElement. For example, in the following HTML code, the button is the tag name of the HTML element:

<button id="gbqfba" class="gbqfba" name="btnK" aria-label="Google Search">

In the preceding code, the button is the tag name of the HTML element.

The API syntax for the getTagName() method is as follows:

java.lang.String getTagName()

The return type of the preceding method is String, and it returns the tag name of the target element.

The following is the code that returns the tag name of the Search button:

@Test
public void elementGetTagNameExample() {
WebElement searchButton = driver.findElement(By.className("search-button"));
System.out.println("Html tag of the button is: "
+ searchButton.getTagName());
}

The preceding code uses the getTagName() method to get the tag name of the Search button element. The output of the code is as expected:

Html tag of the button is: button
主站蜘蛛池模板: 高淳县| 嫩江县| 双牌县| 屯留县| 黑龙江省| 高要市| 潮安县| 临颍县| 姜堰市| 浦县| 辉县市| 四子王旗| 潞城市| 公安县| 北宁市| 修文县| 东宁县| 恭城| 通城县| 永和县| 百色市| 阳原县| 渑池县| 拉萨市| 罗甸县| 枣强县| 平山县| 黄浦区| 南宫市| 凤阳县| 唐河县| 沂南县| 尼玛县| 吴旗县| 安西县| 泾阳县| 察雅县| 仁化县| 新兴县| 上饶市| 瑞金市|