本文介绍了获取使用量角器所有元素属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
根据该文件,以获得通过名称的单一属性,您可以使用的 .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', ... });更多推荐
获取使用量角器所有元素属性
发布评论