尝试使用量角器选择消息时带外索引

时间:2016-10-14 19:53:03

标签: javascript testing xpath protractor

我正在尝试使用此HTML代码选择警告消息“unassigned amount ..” HTML code for warning message

我尝试使用这行代码

选择它
  var warning=element.all(by.xpath('.//span[.="Unassigned Amount = 20.00"]')).filter(function (elm) {
    return elm.isDisplayed().then(function (isDisplayed) {
        return isDisplayed;
    });
});

但是我从量角器得到了这个错误: Error Transcript written below

Message:
    Failed: Index out of bound. Trying to access element at index: 0, but there are only 0 elements that match locator By(xpath, .//span[.="Unassigned Amount = 20.00"]

1 个答案:

答案 0 :(得分:0)

我怀疑你在XPath表达式中的严格相等检查是问题,因为文本周围有额外的空格。试试contains()

.//span[contains(., "Unassigned Amount = 20.00")]

您也可以使用by.cssContainingText locator解决问题:

element.all(by.cssContainingText("span[data-for=APIInvoiceAmount]", "Unassigned Amount = 20.00"))