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

The getText() method

The getText method can be called from all the WebElements. It will return visible text if the element contains any text on it, otherwise it will return nothing.  The API syntax for the getText() method is as follows:

java.lang.String getText()

There is no input parameter for the preceding method, but it returns the visible innerText string of the WebElement if anything is available, otherwise it will return an empty string.

The following is the code to get the text present on the Site notice element present on the example application Homepage:

@Test
public void elementGetTextExample() {
WebElement siteNotice = driver.findElement(By
.className("global-site-notice"));

System.out.println("Complete text is: "
+ siteNotice.getText());
}

The preceding code uses the getText() method to fetch the text present on the Site notice element, which returns the following:

Complete text is: This is a demo store. Any orders placed through this store will not be honored or fulfilled.

主站蜘蛛池模板: 呈贡县| 通河县| 商丘市| 金寨县| 阿克| 兰西县| 伊宁县| 无为县| 夏河县| 汾西县| 屏东市| 武义县| 泸定县| 石河子市| 万年县| 琼海市| 左贡县| 阿坝| 昌图县| 昌黎县| 威海市| 蒲江县| 普兰县| 时尚| 内黄县| 岳阳市| 迁西县| 花莲市| 皮山县| 丹寨县| 九寨沟县| 九寨沟县| 乐山市| 东安县| 阳城县| 洛浦县| 阳朔县| 夏邑县| 顺义区| 祁东县| 乾安县|