使用局部变量调用时,量角器.get不是一个函数



请考虑以下代码:

//CL.DCBS_List_AllElements = $$('#directClassBased > option')

this.shouldMatchDCBSList = async function () {
        var DCBSItems = await CL.DCBS_List_AllElements;
        console.log('Test Text = '+await CL.DCBS_List_AllElements.get(3).getText());
        console.log('Test Text 2 = '+await DCBSItems.get(4).getText());

当我执行此代码时,first console.log(console.log('test text =' 等待cl.dcbs_list_alledement.get(3(.getText(((.getText(((;(按预期返回文本。但是对于下一个,当我将其用作变量时("等待dcbsitems.get(4(.getText(("(,它给我以下错误:

失败:dcbsitems.get不是函数

这很奇怪,因为我可以在使用参数/变量传递元素之前返回文本。我花了很多时间修复它,但现在不起作用。我们该如何修复?

如果您在等待元素arrarayfinder,则将获得一系列elementFinders。请参阅https://github.com/angular/protractor/blob/master/lib/lement.ts#l535

调用 ElementArrayFinder.get(index)时,量角器将在elementArrayfinder对象中获取index。如果您等待元素arrarayfinder,您将获得一个数组。因此,在这种情况下,您使用DCBSItems,而不是调用.get,您应该致电await DCBSItems[4].getText()

最新更新