我正在尝试获取具有相同类的元素之一的Text。但是我使索引脱离了键错误。任何帮助将不胜感激!
下面是确切的错误:
失败:索引超出范围。尝试访问索引为0的元素,但是 只有0个与定位符By(xpath, // div [包含(@ class,'partial className')])
下面是代码的快照:
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);
});
});
答案 0 :(得分:0)
您可以共享loginloc []的代码吗?
很可能,从数组返回的元素数为0,并且您试图在不存在的数组的第0个元素上获取getText()。
此外,最好在以下代码段中使用
:this.loginloc['CurrentProgrammeTitle'].isPresent().then((output) => {
if(output){ //checking if the element is present, then trying to execute next steps
// do other work here
}
});