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

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.

主站蜘蛛池模板: 景东| 安龙县| 陈巴尔虎旗| 清流县| 内丘县| 曲靖市| 靖州| 巩义市| 玉屏| 东平县| 芒康县| 吉水县| 永善县| 永定县| 衡山县| 天津市| 阳春市| 铁岭市| 启东市| 开封县| 双牌县| 泰州市| 曲周县| 威宁| 云安县| 建平县| 梁河县| 盐亭县| 兰西县| 永昌县| 凤凰县| 迭部县| 景德镇市| 抚远县| 黔东| 方城县| 开封市| 区。| 梧州市| 沾化县| 凉城县|