NightwatchJS .elements returning string and not objects

孤街醉人 提交于 2019-12-04 05:01:53

I struggled on this one for a little bit until I went through some of the Selenium documentation.

Essentially that is what's expected to return. Those ELEMENT items are WebElement JSON objects. You can use some of the Selenium commands to try and find additional information on them 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
   }
}

You can see the list of commands on selenium here: http://nightwatchjs.org/api#protocol

Lastly, the ID that's in the documentation there is referring to that element.ELEMENT above.

Hope that helps!

Abitha

when I try to access a particular attribute and validate its value. The webelement chosen is different for each run.

My piece of code here

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}`);
                   }
                });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!