我希望通过其aria-label获取ng-repeater元素,但是想要点击此转发器元素的相应不同标签。我怎么能用过滤器做到这一点。
Web Page:
<workspace-group-handler ng-if="!inputCache.search" ng-repeat="group in groups" group="group" class=""><!---->
<!----><workspace-tile tabindex="0" aria-label="Test" edit-mode="$ctrl.editMode" workspace="$ctrl.group" ng-if="$ctrl.group.type === 'workspace' &&
<div class="tile" ng-class="{'selected-tile': isSelected}" ng-click="openWorkspace($ctrl.workspace); $ctrl.toggleSelected($ctrl.workspace)" ng-right-click="toggleDropdown($event)" aria-haspopup="true" dnd-draggable="$ctrl.workspace" dnd-dragstart="$ctrl.notifyDragstart()" dnd-dragend="$ctrl.notifyDragend()" role="button" tabindex="0" draggable="true">
<div class="ws-icon">
我正在尝试关注:
this.AllWorkspace = element.all(by.repeater('group in groups'));
this.WSLabel = this.AllWorkspace.all(by.css('workspace-tile'));
this.WSIcon = this.AllWorkspace.all(by.css('div .ws-icon'));
WSLabel.filter(function(elem, index) {
return elem.getAttribute("aria-label").then(function(text) {
return text.toUppercase() === 'TEST', index; //want to return index and element both not sure how to do this
});
}).then(function(filteredElements, index) {
console.log("Workspace Name found click on it");
this.WSIcon.get(index).click();
});
如何使用过滤器返回元素索引?基于文本匹配,我想获取此元素的索引,并希望使用相同的索引来单击另一个元素。
答案 0 :(得分:0)
您可以将每个元素详细信息添加到对象中,并将对象推送到数组中。应该可以使用element.all()
的每个方法var details = [];
WSLabel.each(function (elem,index) {
elem.getText().then(function (text) {
if (text === 'TEST') {
var obj = {};
obj.text = text;
obj.element = elem;
obj.index = index;
details.push(obj);
}
});
});