Search for multiple elements on the page, starting from the document root. The located elements will be returned as web element JSON objects.
First argument to be passed is the locator strategy, which is detailed on the WebDriver docs.

The locator strategy can be one of:

  • css selector
  • link text
  • partial link text
  • tag name
  • xpath

Usage

.elements(using, value, callback)

Parameters

Name Type description
using string

The locator strategy to use.

value string

The search target.

callback function

Callback function to be invoked with the result when the command finishes.

Example

module.exports = {
 'demo Test' : function(browser) {
    browser.elements('css selector', 'ul li', function(result) {
      console.log(result.value)
    });
  },

  'es6 async demo Test': async function(browser) {
    const result = await browser.elements('css selector', 'ul li');
    console.log('result value is:', result.value);
  },

  'page object demo Test': function (browser) {
     var nightwatch = browser.page.nightwatch();
     nightwatch
       .navigate()
       .assert.titleContains('Nightwatch.js');

     nightwatch.api.elements('@featuresList', function(result) {
       console.log(result);
     });

     browser.end();
  }
}

W3C WebDriver spec