2015-04-27 41 views
1

我知道过去以某种不同形式询问了问题,但仍未找到确切答案。量角器通过绑定点击中继器中的特定元素

我需要在转发器中找到一个元素并点击它。 转发器是一个应用程序的列表,我需要找到特定应用程序的属性'displayName'等于特定变量(例如“appName1”)。

这是中继器:

<div class="col-md-3 ng-scope" ng-repeat="app in userApps"> <a data-ui-sref="myAppById({appId:app.id})" class="square_container" href="/developers/myApps/ab7d4369-a2da-4bc5-92a5-a19a1af2db1d"> <strong class="app-display-name ng-binding">appName</strong>... 

这仅仅是一个部分。

我需要在userApps中找到应用程序,例如它的displayName等于“appName1”,然后单击它。

回答

2

有多种方式来查找所需的元素,但我想链element.all()element()和使用by.xpath() locator strategy

var a = element.all(by.repeater("app in userApps")).element(by.xpath(".//a[strong = 'appName1']")); 
a.click(); 

或者,使用filter()

element.all(by.repeater("app in userApps")).filter(function (elm) { 
    return elm.evaluate("app.displayName").then(function (displayName) { 
     return displayName === "appName1"; 
    }); 
}).then(function (elms) { 
    var link = elms[0].element(by.tagName("a")); 
    link.click(); 
}); 
+0

谢谢回答。当试图我得到一个错误:TypeError:对象[对象对象]没有方法的'元素' – user2880391

+0

@ user2880391感谢您检查,你使用什么量角器版本?尝试升级到最新,肯定会支持链接元素和element.all。 – alecxe

+0

嘿,我已升级到最新(2.0.0),仍然得到该错误。 – user2880391

相关问题