You can locate all elements having (click)
attribute and check the .count()
:
expect($$("[\(click\)]").count()).toBeGreaterThan(0);
where $$
is a shortcut to element.all(by.css())
. [\(click\)]
CSS selector would match all elements having (click)
attribute. Note that you have to escape parenthesis since they have a special meaning in CSS selectors.
Another option would be to use .filter()
:
var elements = $$("*").filter(function (elm) {
return elm.getAttribute("(click)").then(function (attributeValue) {
return !!attributeValue;
});
});
expect(elements.count()).toBeGreaterThan(0);
Or, use an XPath to match all elements having a (click)
attribute:
var elements = element.all(by.xpath('//*[@*[name() = "(click)"]]'))
expect(elements.count()).toBeGreaterThan(0);
Another weird option would be to use the fresh by.js()
locator:
var elements = element.all(by.js(function() {
function getAllElementsWithAttribute(attribute)
{
var matchingElements = [];
var allElements = document.getElementsByTagName('*');
for (var i = 0, n = allElements.length; i < n; i++)
{
if (allElements[i].getAttribute(attribute) !== null)
{
// Element exists with attribute. Add to array.
matchingElements.push(allElements[i]);
}
}
return matchingElements;
}
return getAllElementsWithAttribute("(click)");
}));
expect(elements.count()).toBeGreaterThan(0);
getAllElementsWithAttribute()
taken from here.