Dheeraj G
Dheeraj G

Reputation: 1

Failed: Index out of bound. Trying to access element at index: 0 error when I try to access through element.all in protractor

I'm trying to getText for one of the elements having same class. But I'm getting Index out of bond error. Any help would be appreciated!

Below is the exact error :

Failed: Index out of bound. Trying to access element at index: 0, but there are only 0 elements that match locator By(xpath, //div[contains(@class,'partial className')])

Below is the snapshot of the code:

this.loginloc['CurrentProgrammeTitle'].isPresent().then(() => {
  this.loginloc['CurrentProgrammeTitle'].getText().then(currentTitle => {
    selectedChannelTitle = currentTitle;
    console.log('Current Title :' + selectedChannelTitle);
  });
  this.loginloc['NextProgrammeTitle'].getText().then(nextTitle => {
    nextChannelTitle = nextTitle;
    console.log('Next Title :' + nextChannelTitle);
  });
});

Upvotes: 0

Views: 991

Answers (1)

rk30
rk30

Reputation: 136

Can you share code of loginloc[].

It is probable, number of elements returned from the array is 0 and you are trying to getText() on the 0th element in array which doesn't exist.

Also, it would be better to use below snippet:

this.loginloc['CurrentProgrammeTitle'].isPresent().then((output) => {
  if(output){ //checking if the element is present, then trying to execute next steps
   // do other work here
  }
});

Upvotes: 0

Related Questions