Failed: Index out of bound. Trying to access element at index: 0 error when I try to access through...
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);
});
});
javascript automation protractor indexoutofboundsexception
add a comment |
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);
});
});
javascript automation protractor indexoutofboundsexception
4
It means it is returning zero elements and calling.getText()is failing as there are no elements to get text from.
– Ryan Wilson
Nov 19 '18 at 16:32
Yes @RyanWilson, but not sure, the previous condition this.loginloc['CurrentProgrammeTitle'].isPresent() is being executed, and in the next statement returning zero elements
– Dheeraj G
Nov 19 '18 at 16:34
Then it is another portion of code which you are not showing that is the issue, more than likely somewhere that you try to get a div by xpath that contains class, partial className;
– Ryan Wilson
Nov 19 '18 at 16:36
there can be many reasons for that. If I were you I would double check that the locator is right by pausing testing before failure and exploring document. Then there is a possibility that the element you're looking for is located inside iframe (a page inside of a page)
– Sergey Pleshakov
Nov 19 '18 at 18:55
add a comment |
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);
});
});
javascript automation protractor indexoutofboundsexception
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);
});
});
javascript automation protractor indexoutofboundsexception
javascript automation protractor indexoutofboundsexception
asked Nov 19 '18 at 16:30
Dheeraj GDheeraj G
1
1
4
It means it is returning zero elements and calling.getText()is failing as there are no elements to get text from.
– Ryan Wilson
Nov 19 '18 at 16:32
Yes @RyanWilson, but not sure, the previous condition this.loginloc['CurrentProgrammeTitle'].isPresent() is being executed, and in the next statement returning zero elements
– Dheeraj G
Nov 19 '18 at 16:34
Then it is another portion of code which you are not showing that is the issue, more than likely somewhere that you try to get a div by xpath that contains class, partial className;
– Ryan Wilson
Nov 19 '18 at 16:36
there can be many reasons for that. If I were you I would double check that the locator is right by pausing testing before failure and exploring document. Then there is a possibility that the element you're looking for is located inside iframe (a page inside of a page)
– Sergey Pleshakov
Nov 19 '18 at 18:55
add a comment |
4
It means it is returning zero elements and calling.getText()is failing as there are no elements to get text from.
– Ryan Wilson
Nov 19 '18 at 16:32
Yes @RyanWilson, but not sure, the previous condition this.loginloc['CurrentProgrammeTitle'].isPresent() is being executed, and in the next statement returning zero elements
– Dheeraj G
Nov 19 '18 at 16:34
Then it is another portion of code which you are not showing that is the issue, more than likely somewhere that you try to get a div by xpath that contains class, partial className;
– Ryan Wilson
Nov 19 '18 at 16:36
there can be many reasons for that. If I were you I would double check that the locator is right by pausing testing before failure and exploring document. Then there is a possibility that the element you're looking for is located inside iframe (a page inside of a page)
– Sergey Pleshakov
Nov 19 '18 at 18:55
4
4
It means it is returning zero elements and calling
.getText() is failing as there are no elements to get text from.– Ryan Wilson
Nov 19 '18 at 16:32
It means it is returning zero elements and calling
.getText() is failing as there are no elements to get text from.– Ryan Wilson
Nov 19 '18 at 16:32
Yes @RyanWilson, but not sure, the previous condition this.loginloc['CurrentProgrammeTitle'].isPresent() is being executed, and in the next statement returning zero elements
– Dheeraj G
Nov 19 '18 at 16:34
Yes @RyanWilson, but not sure, the previous condition this.loginloc['CurrentProgrammeTitle'].isPresent() is being executed, and in the next statement returning zero elements
– Dheeraj G
Nov 19 '18 at 16:34
Then it is another portion of code which you are not showing that is the issue, more than likely somewhere that you try to get a div by xpath that contains class, partial className;
– Ryan Wilson
Nov 19 '18 at 16:36
Then it is another portion of code which you are not showing that is the issue, more than likely somewhere that you try to get a div by xpath that contains class, partial className;
– Ryan Wilson
Nov 19 '18 at 16:36
there can be many reasons for that. If I were you I would double check that the locator is right by pausing testing before failure and exploring document. Then there is a possibility that the element you're looking for is located inside iframe (a page inside of a page)
– Sergey Pleshakov
Nov 19 '18 at 18:55
there can be many reasons for that. If I were you I would double check that the locator is right by pausing testing before failure and exploring document. Then there is a possibility that the element you're looking for is located inside iframe (a page inside of a page)
– Sergey Pleshakov
Nov 19 '18 at 18:55
add a comment |
1 Answer
1
active
oldest
votes
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
}
});
Here I have locators in loginloc and below is the xpath I'm using, CurrentProgrammeTitle: element.all(by.xpath("//div[contains(@class,'type_LiveInfoTitle')]")).first(),
– Dheeraj G
Nov 20 '18 at 7:25
Please check your location once again, I believe it is wrong.
– rk30
Nov 20 '18 at 9:24
Also, unless you are checking output of isPresent() is true or false, you shouldn't be writing getText() on it. Unless you are sure it is visible.
– rk30
Nov 20 '18 at 9:25
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378949%2ffailed-index-out-of-bound-trying-to-access-element-at-index-0-error-when-i-tr%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
}
});
Here I have locators in loginloc and below is the xpath I'm using, CurrentProgrammeTitle: element.all(by.xpath("//div[contains(@class,'type_LiveInfoTitle')]")).first(),
– Dheeraj G
Nov 20 '18 at 7:25
Please check your location once again, I believe it is wrong.
– rk30
Nov 20 '18 at 9:24
Also, unless you are checking output of isPresent() is true or false, you shouldn't be writing getText() on it. Unless you are sure it is visible.
– rk30
Nov 20 '18 at 9:25
add a comment |
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
}
});
Here I have locators in loginloc and below is the xpath I'm using, CurrentProgrammeTitle: element.all(by.xpath("//div[contains(@class,'type_LiveInfoTitle')]")).first(),
– Dheeraj G
Nov 20 '18 at 7:25
Please check your location once again, I believe it is wrong.
– rk30
Nov 20 '18 at 9:24
Also, unless you are checking output of isPresent() is true or false, you shouldn't be writing getText() on it. Unless you are sure it is visible.
– rk30
Nov 20 '18 at 9:25
add a comment |
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
}
});
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
}
});
answered Nov 20 '18 at 6:23
rk30rk30
1366
1366
Here I have locators in loginloc and below is the xpath I'm using, CurrentProgrammeTitle: element.all(by.xpath("//div[contains(@class,'type_LiveInfoTitle')]")).first(),
– Dheeraj G
Nov 20 '18 at 7:25
Please check your location once again, I believe it is wrong.
– rk30
Nov 20 '18 at 9:24
Also, unless you are checking output of isPresent() is true or false, you shouldn't be writing getText() on it. Unless you are sure it is visible.
– rk30
Nov 20 '18 at 9:25
add a comment |
Here I have locators in loginloc and below is the xpath I'm using, CurrentProgrammeTitle: element.all(by.xpath("//div[contains(@class,'type_LiveInfoTitle')]")).first(),
– Dheeraj G
Nov 20 '18 at 7:25
Please check your location once again, I believe it is wrong.
– rk30
Nov 20 '18 at 9:24
Also, unless you are checking output of isPresent() is true or false, you shouldn't be writing getText() on it. Unless you are sure it is visible.
– rk30
Nov 20 '18 at 9:25
Here I have locators in loginloc and below is the xpath I'm using, CurrentProgrammeTitle: element.all(by.xpath("//div[contains(@class,'type_LiveInfoTitle')]")).first(),
– Dheeraj G
Nov 20 '18 at 7:25
Here I have locators in loginloc and below is the xpath I'm using, CurrentProgrammeTitle: element.all(by.xpath("//div[contains(@class,'type_LiveInfoTitle')]")).first(),
– Dheeraj G
Nov 20 '18 at 7:25
Please check your location once again, I believe it is wrong.
– rk30
Nov 20 '18 at 9:24
Please check your location once again, I believe it is wrong.
– rk30
Nov 20 '18 at 9:24
Also, unless you are checking output of isPresent() is true or false, you shouldn't be writing getText() on it. Unless you are sure it is visible.
– rk30
Nov 20 '18 at 9:25
Also, unless you are checking output of isPresent() is true or false, you shouldn't be writing getText() on it. Unless you are sure it is visible.
– rk30
Nov 20 '18 at 9:25
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378949%2ffailed-index-out-of-bound-trying-to-access-element-at-index-0-error-when-i-tr%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
4
It means it is returning zero elements and calling
.getText()is failing as there are no elements to get text from.– Ryan Wilson
Nov 19 '18 at 16:32
Yes @RyanWilson, but not sure, the previous condition this.loginloc['CurrentProgrammeTitle'].isPresent() is being executed, and in the next statement returning zero elements
– Dheeraj G
Nov 19 '18 at 16:34
Then it is another portion of code which you are not showing that is the issue, more than likely somewhere that you try to get a div by xpath that contains class, partial className;
– Ryan Wilson
Nov 19 '18 at 16:36
there can be many reasons for that. If I were you I would double check that the locator is right by pausing testing before failure and exploring document. Then there is a possibility that the element you're looking for is located inside iframe (a page inside of a page)
– Sergey Pleshakov
Nov 19 '18 at 18:55