clearValue
Overview
Use the clearValue
command to clear the value of an <input>
or <textarea>
element.
warning
Make sure you can interact with the element before applying this command.
You won't be able to clear the value of an element that is disabled or in read-only mode.
Usage
await browser.$(selector).clearValue();
Usage Examples
it("should demonstrate the clearValue command", async ({ browser }) => {
const elem = await browser.$(".input");
await elem.setValue("test123");
const value = await elem.getValue();
console.log(value); // outputs: 'test123'
await elem.clearValue();
value = await elem.getValue();
assert.equal(value, ""); // true
});
Related Commands
References
We'd like to give credit to the original WebdriverIO docs article, from which we drew some information while writing our version.