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

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.

主站蜘蛛池模板: 中西区| 彩票| 庆安县| 威信县| 汉中市| 伊吾县| 湟源县| 筠连县| 揭阳市| 桂平市| 漳浦县| 襄垣县| 昭苏县| 安宁市| 揭东县| 盐山县| 隆昌县| 原阳县| 大化| 五峰| 桂阳县| 赤城县| 黄冈市| 孟村| 林州市| 清河县| 永登县| 阿图什市| 武威市| 安远县| 乐东| 灯塔市| 梁平县| 深水埗区| 逊克县| 龙南县| 昌乐县| 綦江县| 博罗县| 陆良县| 岳西县|