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

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.

主站蜘蛛池模板: 保山市| 连平县| 马边| 伊金霍洛旗| 辉南县| 永善县| 和平区| 丰顺县| 卢龙县| 宜阳县| 精河县| 萝北县| 辰溪县| 滦平县| 寻乌县| 平顶山市| 正定县| 安溪县| 河间市| 乌拉特前旗| 来安县| 霞浦县| 平远县| 邓州市| 象山县| 林甸县| 漾濞| 浮山县| 都安| 车险| 日土县| 华池县| 苍溪县| 顺义区| 松潘县| 文登市| 安丘市| 东至县| 阜平县| 惠州市| 泊头市|