使用 Nightwatch,如何从 ELEMENT 实体获取 DOM 元素及其属性? [英] Using Nightwatch, how do you get the DOM element, and it's attributes from the ELEMENT entity?

查看:52
本文介绍了使用 Nightwatch,如何从 ELEMENT 实体获取 DOM 元素及其属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到了一些奇怪的行为,其中存在于视图中的元素没有被 nightwatch 定位.为了准确查看可见的内容,我想遍历 nightwatch 已打开的视图,并获取它可以找到的每个元素的列表,并从该结果中获取有关这些元素是什么的相关信息.我已经能够通过以下方式找到"所有元素:

I've noticed some strange behavior where elements that are present in the view are not being located by nightwatch. In order to see exactly what is visible, I'd like to iterate through the view that nightwatch has opened, and get a list of every element that it can locate, and get the relevant information from that result about what those elements are. I've been able to 'find' all the elements with the following:

 browser.elements('css selector', 'div', function (elements) {
   elements.value.forEach(function(element){
     console.log('result', element)
   })
 })

问题在于结果是一系列的: { ELEMENT: '0.9107972990792419-3' }

The catch is that the result is a series of these: { ELEMENT: '0.9107972990792419-3' }

我如何从 nightwatch ELEMENT 中获取 class 以及有关该元素的所有其他相关信息?

How do I get the class, and all the other relevant information about the element from the nightwatch ELEMENT?

谢谢!

推荐答案

为此,您需要使用 .elementIdAttribute.

browser.elements('css selector', 'div', function(elements) {
  elements.value.forEach(function(element){
    browser.elementIdAttribute(element.ELEMENT, 'class', function(attribute) {
      console.log(attribute.value);
    });
  });
});

这篇关于使用 Nightwatch,如何从 ELEMENT 实体获取 DOM 元素及其属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆