waitForText(selector, expectedValue [,options])


This is a TDK feature

This is not supported in Testim's visual editor

Waits for an element to exist on the screen and its text equal to expected value.

  • selector {string | TDKStepLocator} a CSS selector or smart locator.
  • expectedValue { string or RegExp } the expected value of the element
  • options {object}
    • checkVisibility { boolean } whether or not to wait for the element to be user visible - defaults to true.
  • returns: Promise that fulfills when the element is present and the element text as expected.

For example:

// ✅ wait for the element to contain the word 'Hello!'
await waitForText('.someSelector', 'Hello!');
// ✅ wait for the element text to contain a `@`
await waitForText('.someSelector', /.*@.*/);
// ✅ same as above but with a smart locator
await waitForText(l('.someSelector'), /.*@.*/);
// ✅ wait for an element to contain a '@' but disregard it being visible
await waitForText('.someSelector', /.*@.*/, {
  checkVisibility: false
// ❌ need to pass text in
await waitForText('.someSelector');

// ❌ arguments are positional and not an object
await waitForText({
  selector: '.someSelector',
  text: 'foo',
  checkVisibility: false

Full Example:

'use strict';

const { go, waitForElement, test } = require('testim');

test("waitForElement", async () => {
    await go('http://jsbin.testim.io/quh/1');
    await waitForText('button', 'Test');