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

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.

主站蜘蛛池模板: 英山县| 英超| 鹤庆县| 永善县| 宣城市| 综艺| 吉木萨尔县| 象州县| 无极县| 葫芦岛市| 阳西县| 万山特区| 深水埗区| 湖南省| 巴东县| 嘉禾县| 甘洛县| 青岛市| 聊城市| 长泰县| 衡阳县| 东宁县| 湘阴县| 凤阳县| 准格尔旗| 彰化市| 满洲里市| 南漳县| 讷河市| 双辽市| 托克逊县| 马山县| 比如县| 响水县| 任丘市| 富民县| 金平| 永兴县| 宽城| 尤溪县| 周宁县|