click(selector [, options])

🚧

This is a TDK feature

This is not supported in Testim's visual editor

Clicks the given element on the screen, clicks on the element in its center by default.

  • selector {string | TDKStepLocator} a CSS selector or smart locator.
  • options {object} optional extra arguments
    • button {'left'|'right'} what button to press. (defaults to left)
    • offset {object}:
      • x {number} x position in element to click in
      • y {number} y position in element to click in
  • returns: Promise which fulfills when the element matching selector has been clicked or rejected if the element is not found.

For example:

// ✅ click on the first H1 in the page
await click('h1');
// ✅ right-click on the first H2 in the page
await click('h2', { button: 'right' });
// ✅ click on the first H1 in the page in offset 10, 10
await click('h1', { offset: {x: 10, y: 10 }});

// ✅ click on the login page, recorded as a locator
// from the Testim UI
await click(l('login-page'))

// ❌ you need to tell it what element to click on
await click({ button: 'right' });
// ❌ offset takes an object parameter
await click('h1', { offset: 15 });

Full test example:

'use strict';

const expect = require('chai').expect;
const { go, click, test, text } = require('testim');

describe('clicking', () => {
    test('clicking on a button', async () => {
        await go('http://jsbin.testim.io/ner/1');
        await click('#test');
    });
});