Click

Clicks a webpage element.

t.click( selector [, options] )
Parameter Type Description
selector Function | String | Selector | Snapshot | Promise Identifies the webpage element being clicked. See Selecting Target Elements.
options (optional) Object A set of options that provide additional parameters for the action. See Click Action Options.

The following example shows how to use the t.click action to check a checkbox element.

import { Selector } from 'testcafe';

const checkbox = Selector('#testing-on-remote-devices');

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

test('Click a check box and check its state', async t => {
    await t
        .click(checkbox)
        .expect(checkbox.checked).ok();
});

The next example uses the options parameter to set the caret position in an input box.

import { Selector } from 'testcafe';

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

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

test('Click Input', async t => {
    await t
        .typeText(nameInput, 'Peter Parker')
        .click(nameInput, { caretPos: 5 })
        .keyPress('backspace')
        .expect(nameInput.value).eql('Pete Parker');
});