- Selenium WebDriver 3 Practical Guide
- Unmesh Gundecha Satya Avasarala
- 144字
- 2021-08-13 16:08:11
The clear() method
The clear action is similar to the sendKeys() method, which is applicable for the textbox and textarea elements. This is used to erase the text entered in a WebElement using the sendKeys() method. This can be achieved using the Keys.BACK_SPACE enum, but WebDriver has given us an explicit method to clear the text easily. The API syntax for the clear() method is as follows:
void clear()
This method doesn't take any input and doesn't return any output. It is simply executed on the target text-entry element.
Now, let's see how we can clear text that is entered in the Search box. The code example for it is as follows:
@Test
public void elementClearExample() {
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys(Keys.chord(Keys.SHIFT,"phones"));
searchBox.clear();
}
We have used the WebElement's clear() method to clear the text after typing phones into the Search box.
推薦閱讀
- Application Development with Qt Creator(Second Edition)
- 自動駕駛網絡:自智時代的網絡架構
- Mastering Machine Learning for Penetration Testing
- 5G承載網網絡規劃與組網設計
- Learning Karaf Cellar
- 網絡互聯技術(實踐篇)
- 企業私有云建設指南
- 中小型局域網組建、管理與維護實戰
- 城域網與廣域網(第2版)
- 物聯網之霧:基于霧計算的智能硬件快速反應與安全控制
- VMware NSX網絡虛擬化入門
- 網管工具使用與技巧大全
- 6G:面向2030年的移動通信
- 從實踐中學習手機抓包與數據分析
- Hands-On Microservices with Node.js