- Selenium WebDriver 3 Practical Guide
- Unmesh Gundecha Satya Avasarala
- 162字
- 2021-08-13 16:08:09
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.
推薦閱讀
- C++黑客編程揭秘與防范
- 重新定義Spring Cloud實戰(zhàn)
- Learning Karaf Cellar
- Windows Server 2003 Active Directory Design and Implementation: Creating, Migrating, and Merging Networks
- 物聯(lián)網(wǎng)時代
- Mastering JavaFX 10
- Spring 5.0 Projects
- Kong網(wǎng)關(guān):入門、實戰(zhàn)與進階
- 基于性能的保障理論與方法
- 6G:面向2030年的移動通信
- 網(wǎng)絡(luò)綜合布線(第2版)
- 移動物聯(lián)網(wǎng):商業(yè)模式+案例分析+應(yīng)用實戰(zhàn)
- 全聯(lián)網(wǎng)標(biāo)識服務(wù)
- Getting Started with tmux
- 圖解物聯(lián)網(wǎng)