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

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.

主站蜘蛛池模板: 西乌珠穆沁旗| 曲水县| 松潘县| 卓资县| 庆云县| 怀安县| 成安县| 三亚市| 双辽市| 托克逊县| 陆良县| 陆丰市| 德安县| 行唐县| 偃师市| 绥中县| 拉萨市| 安多县| 南和县| 湘乡市| 云龙县| 静海县| 湖州市| 通江县| 库车县| 抚松县| 介休市| 阿鲁科尔沁旗| 阿瓦提县| 景谷| 临潭县| 崇礼县| 天津市| 繁峙县| 安达市| 辉南县| 靖远县| 吉木乃县| 木里| 石屏县| 连州市|