繁体   English   中英

失败:索引超出范围。 尝试访问量角器中的element.all时,尝试访问索引处的元素:0错误

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

我正在尝试为具有相同类的元素之一获取文本。 但是我使索引脱离了键错误。 任何帮助,将不胜感激!

以下是确切的错误:

失败:索引超出范围。 尝试访问索引为0的元素,但只有0个与定位符By(xpath,// div [contains(@ 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);
  });
});

您可以共享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
  }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM