【问题标题】:- Failed: Index out of bound. Trying to access element at index: 0, but there are only 0 elements that match locator By.xpath- 失败:索引超出范围。尝试访问索引处的元素:0,但只有 0 个元素与定位器 By.xpath 匹配
【发布时间】:2016-10-17 20:54:11
【问题描述】:

量角器投掷错误失败:索引超出范围。试图访问 index: 0 处的元素,但只有 0 个元素与定位器 By.xpath 匹配

var eleXpath = '//*[@data-qa-class="tile" and descendant::*[normalize-space(.)="Weights"]]//*[@options="ctrl.grid.options"]/*[contains(@class, "slick-frozen-rows") and not(contains(@class, "multi-header"))]//*[contains(@class, "slick-pane slick-pane-bottom slick-pane-left")]//*[contains(@class, "slick-row") and descendant::*[normalize-space(.)="88579YAE"]]';

var rowReferenceXpath = element.all(by.xpath(eleXpath)).get(rowIndex);

rowReference.isPresent().then(function (isRowPresent) {
  if (!isRowPresent) {
    // If required row is not found reject the promise with error message
    defer.reject('"' + rowName + '" row is not found in the calculated reported.');
  } else {
    // Get the "style" attribute value of the row
    var eleRefs = rowReference.getAttribute('style');
  };

抛出错误

  • 失败:索引超出范围。试图访问索引为 0 的元素,但只有 0 个元素与定位器匹配 By.xpath("//[@data-qa-class="tile" and descendant::[normalize- space(.)="Weights"]]//[@options="ctrl.grid.options"]/[contains(@class, "slick-frozen-rows") 和 not(contains (@class, "multi-header"))]//[contains(@class, "slick-pane slick-pane-bottom slick-pane-left")]//[contains(@类, "slick-row") 和后代::*[normalize-space(.)="88579YAE"]]")

【问题讨论】:

  • 您正在使用的 xpath 没有返回任何元素。这就是量角器抛出此错误的原因。也发布您的 HTML 代码。
  • 感谢您的意见,将分享它

标签: protractor gulp-protractor protractor-net


【解决方案1】:

看起来您可能在 eleXpath 上错过了转义

var eleXpath = '//[@data-qa-class="tile" and descendant::[normalize-space(.)="Weights"]]//[@options="ctrl.grid.options" ]/[contains(@class, "slick-frozen-rows") 和 not(contains(@class, "multi-header"))]//[contains(@class, "slick-pane slick-pane-bottom slick -pane-left")]//[包含(@class, "slick-row") 和后代::*[normalize-space(.)="88579YAE"]]';

var eleXpath = '//[@data-qa-class="tile" and descendant::[normalize-space(.)="Weights"]]//[@options="ctrl.grid.options" ]//[contains(@class, "slick-frozen-rows") 和 not(contains(@class, "multi-header"))]//[contains(@class, "slick-pane slick-pane-bottom slick-pane-left")]//[contains(@class, "slick-row") and descendant::*[normalize-space(.)="88579YAE"]]';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-16
    • 2013-05-26
    • 2012-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-11
    相关资源
    最近更新 更多