Locate element by a presence of a custom attribute

2019-09-20 17:50发布

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条回答
唯我独甜
2楼-- · 2019-09-20 18:22

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.

查看更多
登录 后发表回答