获取使用量角器所有元素属性

编程入门 行业动态 更新时间:2024-10-26 06:37:23
本文介绍了获取使用量角器所有元素属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

根据该文件,以获得通过名称的单一属性,您可以使用的 .getAttribute() 在 WebElement :

According to the documentation, to get a single attribute by name you can use .getAttribute() on a WebElement:

var myElement = element(by.id('myId')); expect(myElement.getAttribute('myAttr')).toEqual('myValue');

但我怎么能得到所有的元素具有的属性?

But how can I get all of the attributes that an element has?

有没有关于在量角器API 这个用例/功能信息。

There is no information about this use case/functionality in the Protractor API.

推荐答案

您可以扩展JavaScript的元素键入并添加的getAttributes()功能:

You can expand javascript's Element type and add getAttributes() function:

Element.prototype.getAttributes = function() { return (function (node) { var attrs = {}; for (var i=0;i<node.length;i++) { attrs[node.item(i).name] = node.item(i).value; } return attrs; })(this.attributes); };

演示

然后就可以使用您使用一个属性同样的方法测试属性的完整性:

then you can test integrity of attributes using the same method you use for one attribute:

var myElement = element(by.id('myId')); expect(myElement.getAttributes()).toEqual({'attr1': 'value1', 'attr1': 'value1', ... });

更多推荐

获取使用量角器所有元素属性

本文发布于:2023-11-23 03:33:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619930.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:量角器   属性   元素

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!