Locate element by a presence of a custom attribute

巧了我就是萌 提交于 2019-12-13 08:29:52

问题


How do you locate all those elements that has particular custom attribute in Protractor? I found similar questions on Stackoverflow and on net, but they uses xpath which puts restriction on tag.

element(by.xpath('//div[@custom-attribute]'))

As oppose to above example, I don't want to put restriction on tag since we have different tags with the same custom attribute. I'd like locate all elements with the attribute regardless of tag. Is that possible?


回答1:


You can use a CSS selector locator:

element.all(by.css('[custom-attribute]'));

Or, via the $$ shortcut:

$$('[custom-attribute]');

[custom-attribute] is an attribute selector that would match any element having custom-attribute attribute.



来源:https://stackoverflow.com/questions/40467770/locate-element-by-a-presence-of-a-custom-attribute

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