elements返回字符串而不是对象

elements返回字符串而不是对象

本文介绍了NightwatchJS .elements返回字符串而不是对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用夜表,并尝试遍历元素列表.但是,当我没有得到对象或元素时,却得到了一个字符串数组.

I am using nightwatch and trying to iterate through a list of elements. However, when I don't get objects or elements, but I get an array of strings.

代码

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

返回

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应该返回一个webElements对象吗?

The value should be returning an object of webElements right?

预先感谢

推荐答案

在阅读完一些Selenium文档之前,我一直在为此苦苦挣扎.

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

基本上,这就是预期的结果.这些ELEMENT项是WebElement JSON对象.您可以使用某些Selenium命令来尝试找到有关它们的其他信息,例如:

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
   }
}

您可以在此处查看selenium上的命令列表: http://nightwatchjs.org/api#protocol

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

最后,文档中的ID指向上面的element.ELEMENT.

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

希望有帮助!

这篇关于NightwatchJS .elements返回字符串而不是对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 01:39