NightwatchJS. Elements return a string, not objects

I am using nightwatch and trying to iterate over a list of items. However, when I do not get objects or elements, but get an array of strings.

CODE

browser.elements("css selector", ele, function(r){
    browser.perform(function(){
      console.log("LIST", r);
    })
  })

Return

LIST { sessionId: 'b273b874-c084-4d17-8bbe-a911a170ef25',
  status: 0,
  state: 'success',
  value:
   [ { ELEMENT: '6' },
     { ELEMENT: '7' },
     { ELEMENT: '8' },
     { ELEMENT: '9' },
     { ELEMENT: '10' },
     { ELEMENT: '11' } ],
  class: 'org.openqa.selenium.remote.Response',
  hCode: 995684858 }

value should return the webElements object correctly?

Thanks in advance

+4
source share
2 answers

I struggled with this a bit until I looked through some Selenium docs.

This is essentially the expected return. These ELEMENT elements are WebElement JSON objects. You can use some Selenium commands to try to find additional information about them by doing something like this:

_.each(list.value, function(element, i){ //using underscore instead of for loop.
   browser.elementIdAttribute(element.ELEMENT, 'name', function(result){
       //result.value will contain the name attribute on the element
   }
}

Here you can see the list of selenium commands: http://nightwatchjs.org/api#protocol

, , , . ELEMENT .

, !

+7

​​ . - .

browser.elements('css selector', 'header.modal-header > h2', (results) => {
            results.value.forEach((v, k) => {
               browser.elementIdAttribute(v.ELEMENT, 'tabindex', 
                function (index) {
                   if (index.value !== '-1') {
                        browser.verify.fail(`Expected tab index -1 not found for ContactUs header ${key}`);
                   }
                });
-1

All Articles