。数数();不是函数

.count(); is not a function

所以我一直在试图理解我做错了什么,但我似乎没有理解!

在我继续这里之前是我正在尝试处理的代码

it('Clicked all remove button', async function () {
    // Im assuming here that `getRemoveButtonDesktop()` returns a promise of web element array.
    let allBtns = await element.all(by.className('btn btn-remove btn-outlined desktop'));
    // ElementArrayFinder.count() returns a promise that is resolved into a number
    let countElement = await allBtns.count();
    console.log('Find buttons: ', countElement)

    for (let i = 0; i < countElement; i++) { // let variables are scoped to the immediate enclosing block denoted by { }
        // ElementArrayFinder.first() returns a promise
        const firstRemoveButton = await detailsSpecs.getRemoveButtonDesktop().first();
        await utils.click(firstRemoveButton);
        await browser.sleep(1000) // sleep 1s
    }
});

我得到的错误是:

  1) Details page
       Clicked all remove button:
     TypeError: allBtns.count is not a function
      at Context.<anonymous> (pagesDesktop\detailsPage.js:208:36)
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (internal/process/task_queues.js:93:5)

它应该做的是计算所有 "allBtns" 之后它会根据找到的元素数量循环但它似乎不知道 .count 不是一个函数。

编辑:我在 JS 中使用 Protractor。

getRemoveButtonDesktop = removeButtonDesktop: element.all(by.className('btn btn-remove btn-outlined desktop')), 我做错了什么?

根据文档,all 方法是 not Promise-like,因此更改

let allBtns = await element.all(by.className('btn btn-remove btn-outlined desktop'));

 let allBtns = element.all(by.className('btn btn-remove btn-outlined desktop'));

element.all returns 一个包含 count 方法的 ElementArrayFinder 元素,而 await element.all returns 只是一个简单的元素数组。