Types a key sequence on the DOM element. Can be used to send a sequence of key strokes to an element. Any UTF-8 character may be specified.

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.

sendKeys() will automatically wait for the element to be present (until the specified timeout). If the element is not found, an error is thrown which will cause the test to fail. Starting with v1.2 you can suppress element not found errors by specifying the suppressNotFoundErrors option.

Usage:

.sendKeys(selector, inputValue, [callback])

Parameters:

Name Type description
using
Optional
string

The locator strategy to use. See W3C Webdriver - locator strategies

selector string|object

The selector (CSS/Xpath) used to locate the element. Can either be a string or an object which specifies element properties.

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.

Example:

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

W3C WebDriver spec: