【发布时间】:2018-09-11 18:03:10
【问题描述】:
我正在尝试访问包含在一行中的标签。
此代码有效,但是它会找到该类型的所有标签,而不是特定/父行中的一个:
expect(element(by.xpath("//span[@ng-click='location.viewAudit(audit)'][contains(@class, 'source-name')]")).isPresent()); //label for the source name
这是我失败的代码:
var tableRow = element(by.xpath("//tr[contains(@class, 'ng-scope')][@ng-repeat='audit in location.displayedProfileAudits']")).getWebElement();
expect(tableRow.element(by.xpath("//span[@ng-click='location.viewAudit(audit)'][contains(@class, 'source-name')]")).isPresent()); //label for the source name
这是返回的错误:
Message: TypeError: tableRow.element is not a function
完整的步骤定义:
Then('I should see that a location audit source row has a label for the source', function (callback) {
browser.wait(EC.visibilityOf(listingsPageObj.locationProfileListViewContainer), timeouts.EC_TIMEOUT).then(() => {
browser.wait(EC.visibilityOf(listingsPageObj.locationProfileListViewTable), timeouts.EC_TIMEOUT).then(() => {
browser.wait(() => {
return listingsPageObj.locationProfileListViewTableHeaders.count().then(cnt => (cnt > 0)); //which means that there are audit results displayed
}).then(() => {
//find a row in the list of displayed audits
var tableRow = element(by.xpath("//tr[contains(@class, 'ng-scope')][@ng-repeat='audit in location.displayedProfileAudits']")).getWebElement();
//then verify, within that row, there is a label for the source name
expect(tableRow.element(by.xpath("//span[@ng-click='location.viewAudit(audit)'][contains(@class, 'source-name')]")).isPresent()); //label for the source name
callback();
});
});
});
});
【问题讨论】:
-
您需要拨打
getWebElement吗? -
嗯显然不是...谢谢。
标签: angularjs protractor element qa