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

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
主站蜘蛛池模板: 宣化县| 白玉县| 竹北市| 宾川县| 石狮市| 武威市| 邢台市| 广昌县| 广南县| 沙田区| 锡林浩特市| 定边县| 舒兰市| 太康县| 凯里市| 哈密市| 乌拉特后旗| 新宁县| 沈丘县| 桑植县| 望城县| 赤城县| 精河县| 贵南县| 察雅县| 白水县| 隆昌县| 遂溪县| 嘉祥县| 襄城县| 龙海市| 苗栗县| 和政县| 新宾| 吴川市| 邢台市| 通化市| 比如县| 莆田市| 绥德县| 监利县|