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

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
主站蜘蛛池模板: 绵竹市| 鄂托克旗| 潮州市| 达孜县| 青海省| 丰宁| 京山县| 烟台市| 额尔古纳市| 尼木县| 桐城市| 武夷山市| 镇雄县| 孝昌县| 合水县| 齐河县| 定远县| 三都| 云梦县| 岚皋县| 醴陵市| 玛多县| 济宁市| 泽普县| 新丰县| 澄城县| 五寨县| 济阳县| 扶绥县| 北川| 长治市| 阳朔县| 德阳市| 肇庆市| 留坝县| 都江堰市| 军事| 磴口县| 兰坪| 上蔡县| 萝北县|