Sends some text to an element. Can be used to set the value of a form element or to send a sequence of key strokes to an element. Any UTF-8 character may be specified.

setValue also clears the existing value of the element by calling the clear() beforehand.

An object map with available keys and their respective UTF-8 characters, as defined on W3C WebDriver draft spec, is loaded onto the main Nightwatch instance as browser.Keys.

For more info on working with DOM elements in Nightwatch, refer to the Finding & interacting with DOM Elements guide page.

Usage

                    browser.element(selector).setValue(inputValue)
                

Example

// send some simple text to an input
this.demoTest = function (browser) {
  const result = await browser.element('input[type=text]').setValue('nightwatch');
};

// send some text to an input and hit enter.
this.demoTest = function (browser) {
  const result = await browser.element('input[type=text]').setValue(['nightwatch', browser.Keys.ENTER]);
};

Parameters

Name Type description
inputValue string | array

The text to send to the element or key strokes.

callback
Optional
function

Optional callback function to be called when the command finishes.

W3C WebDriver spec