Reputation: 315
Is it possible to convert the ElementArrayFinder
returned by the results of element.all(....)
into a generic array?
The goal is to store the elements in the array and add more elements to them from result of another element.all()
using push()
.
Upvotes: 2
Views: 741
Reputation: 474003
You can extend ElementArrayFinder
and add an extend()
method concatenating the arrays of internal web elements of both array finders:
protractor.ElementArrayFinder.prototype.extend = function(finder) {
var self = this;
var getWebElements = function() {
return self.getWebElements().then(function(parentWebElements) {
return finder.getWebElements().then(function(newWebElements) {
return parentWebElements.concat(newWebElements);
});
});
};
return new protractor.ElementArrayFinder(this.browser_, getWebElements, this.locator_);
};
Usage:
var arr1 = $$(".myclass");
var arr2 = $$(".someotherclass");
var newArr = arr1.extend(arr2);
expect(newArr.getText()).toEqual(["text1", "text2", "text3"]);
Tested, works for me in a simple test case.
Upvotes: 1