- 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.
推薦閱讀
- Application Development with Qt Creator(Second Edition)
- C++黑客編程揭秘與防范
- Windows Server 2003 Active Directory Design and Implementation: Creating, Migrating, and Merging Networks
- Wireshark網(wǎng)絡(luò)分析就這么簡單
- Mastering JavaFX 10
- 4G小基站系統(tǒng)原理、組網(wǎng)及應(yīng)用
- Implementing NetScaler VPX?
- 互聯(lián)網(wǎng)安全的40個智慧洞見(2016)
- 圖神經(jīng)網(wǎng)絡(luò)前沿
- Web用戶查詢?nèi)罩就诰蚺c應(yīng)用
- 物聯(lián)網(wǎng)
- 數(shù)字王國里的虛擬人:技術(shù)、商業(yè)與法律解讀
- 黑客與反黑工具使用詳解
- 物聯(lián)網(wǎng)導(dǎo)論
- 云計算、網(wǎng)絡(luò)安全和網(wǎng)絡(luò)盜竊:網(wǎng)絡(luò)世界防盜初學指南