因此,我一直试图了解自己在做错什么,而我似乎并不了解!
在继续之前,这里是我要尝试的代码
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。
getRemoveButtonDesktop =removeButtonDesktop: element.all(by.className('btn btn-remove btn-outlined desktop')),
我在做什么错?
根据文档,all
方法不像Promise那样,因此请更改
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
返回ElementArrayFinder
包含该count
方法的元素,而await element.all
仅返回一个简单的元素数组。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句