量角器通过绑定点击转发器中的特定元素
protractor click specific element in repeater by binding
我知道这个问题过去曾以不同的形式提出过,但仍然没有找到确切的答案。
我需要在中继器中找到一个元素并单击它。
转发器是应用程序列表,我需要找到属性 '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" 的应用,然后点击它。
有多种方法可以找到所需的元素,但我会链接 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();
});
我知道这个问题过去曾以不同的形式提出过,但仍然没有找到确切的答案。
我需要在中继器中找到一个元素并单击它。 转发器是应用程序列表,我需要找到属性 '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" 的应用,然后点击它。
有多种方法可以找到所需的元素,但我会链接 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();
});