0
votes

Protractor throwing error Failed: Index out of bound. Trying to access 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

  • Failed: Index out of bound. Trying to access element at index: 0, but there are only 0 elements that match locator By.xpath("//[@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\"]]")
1
The xpath that your are using is not returning any elements.That is why protractor is throwing this error.Post your HTML code as well. - Sudharsan Selvaraj
Thanks for the input, will share it - shaik

1 Answers

0
votes

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