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

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
主站蜘蛛池模板: 白河县| 黄浦区| 富顺县| 大宁县| 惠来县| 南华县| 通江县| 鹤山市| 昌乐县| 保亭| 武威市| 荔浦县| 竹山县| 青海省| 墨脱县| 尤溪县| 普洱| 六盘水市| 定南县| 乌兰浩特市| 二手房| 正阳县| 离岛区| 平阳县| 东兰县| 苗栗市| 虎林市| 台山市| 盱眙县| 叙永县| 永登县| 宽城| 河曲县| 三门县| 漳平市| 兴城市| 乾安县| 休宁县| 汪清县| 卢龙县| 开鲁县|