text(selector)

🚧

This is a TDK feature

This is not supported in Testim's visual editor

This method is used to extract an element's text content.

  • selector {string | TDKStepLocator} a CSS selector or smart locator for the element whose text we want to get
  • returns: Promise which fulfills with the element's text.
// ✅ get the text of the first h1 header
const header = await text('h1');
// use Chai or another library to write assertions
expect(header).to.equal('Space & Beyond'); 
// ❌ you need to pass an element to `text`
const header = await text();

Full usage example

'use strict';

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

test("text", async () => {
    await go('http://jsbin.testim.io/quh/1');
    await click('button');
    const elementText = await text('body');
    expect(elementText).to.equal('Hello World');
    // hello
});