Skip to main content

setValue

Overview

Use the setValue command to send a sequence of key presses to an element after first clearing the input field.

If the element does not need to be cleared first, use the addValue command.

info

If you want to use special characters, for example, to copy and paste a value from one input to another, use the keys command.

Usage

await browser.$(selector).setValue(value);

Command Parameters

NameTypeDescription
valueString or NumberThe value to set.

Usage Examples

it("should set value for a certain element", async ({ browser }) => {
const input = await browser.$(".input");
await input.setValue("test");
await input.setValue(123);

console.log(await input.getValue()); // outputs: '123'
});

References

We'd like to give credit to the original WebdriverIO docs article, from which we drew some information while writing our version.