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

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.

主站蜘蛛池模板: 余姚市| 潜山县| 雅安市| 临海市| 应城市| 卓资县| 上林县| 若尔盖县| 桂东县| 宾川县| 应城市| 桑植县| 河东区| 土默特左旗| 深圳市| 同德县| 六枝特区| 象州县| 馆陶县| 大新县| 南宫市| 龙南县| 沂源县| 乳山市| 屯留县| 清苑县| 乌兰察布市| 五峰| 久治县| 美姑县| 巫山县| 绿春县| 通化县| 巴里| 全南县| 永年县| 东丽区| 正阳县| 耒阳市| 平陆县| 邛崃市|