Type Text

Types the specified text into an input element.

t.typeText( selector, text [, options] )
Parameter Type Description
selector Function | String | Selector | Snapshot | Promise Identifies the webpage element that will receive input focus. See Selecting Target Elements.
text String The text to be typed into the specified webpage element.
options (optional) Object A set of options that provide additional parameters for the action. See Typing Action Options. If this parameter is omitted, TestCafe sets the cursor to the end of the text before typing, thus preserving the text that is already in the input box.

Use the t.selectText and t.pressKey actions to implement operations such as selecting or deleting text.

The following example shows how to use t.typeText with and without options.

import { Selector } from 'testcafe';

const nameInput = Selector('#developer-name');

fixture `My fixture`
    .page `http://www.example.com/`;

test('Type and Replace', async t => {
    await t
        .typeText(nameInput, 'Peter')
        .typeText(nameInput, 'Paker', { replace: true })
        .typeText(nameInput, 'r', { caretPos: 2 })