Testim Documentation

Welcome to the Testim documentation. You'll find comprehensive guides to help you get started quickly, example code snippets, and tips for being more productive. You will also find details about advanced features that allow you to customize Testim to fit your environment or special testing conditions. Don't worry, we'll support you if you get stuck. Let's jump right in!

Guides    Changelog

click(selector [, options])

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');
    });
});

Updated 26 days ago

click(selector [, options])


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.