- 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.
推薦閱讀
- Web安全防護指南:基礎(chǔ)篇
- 物聯(lián)網(wǎng)智慧安監(jiān)技術(shù)
- 物聯(lián)網(wǎng)安全(原書第2版)
- INSTANT PhpStorm Starter
- TCP/IP入門經(jīng)典(第5版)
- 物聯(lián)網(wǎng)關(guān)鍵技術(shù)及應(yīng)用
- PLC、現(xiàn)場總線及工業(yè)網(wǎng)絡(luò)實用技術(shù)速成
- 物聯(lián)網(wǎng)通信技術(shù)
- 圖解手機元器件維修技巧
- Microservice Patterns and Best Practices
- React Cookbook
- 移動互聯(lián)網(wǎng)新思維
- 圖解物聯(lián)網(wǎng)
- Enterprise ApplicationDevelopment with Ext JSand Spring
- 人際網(wǎng)絡(luò)