shaik
shaik

Reputation: 35

- Failed: Index out of bound. Trying to access element at index: 0, but there are only 0 elements that match locator By.xpath

Protractor throwing error Failed: Index out of bound. Trying to access the element at index: 0, but there are only 0 elements that match locator 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');
  };

Throwing error as

Upvotes: 0

Views: 1498

Answers (1)

Robert Brown
Robert Brown

Reputation: 16

It looks like you might be missing an escape on your eleXpath

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"]]';

versus

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"]]';

Upvotes: 0

Related Questions