Returns the visible text for the element.

For more info on working with DOM elements in Nightwatch, refer to the Finding & interacting with DOM Elements guide page.

Usage

                    browser.element(selector).getText()
                

Example

export default {
  demoTest(browser: NightwatchAPI): void {
    browser.element('#main ul li a.first')
      .getText()
      .assert.contains('custom text');
  },

  async demoTestAsync(browser: NightwatchAPI): Promise<void> {
    const result = await browser.element('#main ul li a.first').getText();
    console.log('element text:', result);
  }
}

Returns

Type description
ScopedValue<string>

W3C WebDriver spec