webdriver.io框架计算elements出现的个数

通过某个元素的length来判断当前的元素共有多少,但是因为dom节点的class和id会有雷同的情况 可以根据实际情况进行加减做判断

async initializeFolder() {
        browser.pause(5000)
        await this.favoriteIcon.waitForClickable()
        await this.favoriteIcon.click()
        browser.pause(6000)
        //let a = await ($$(`li`)).length
        //let count = await ($$(`li`)).length -8
        let count = await ($$('.EmbersNav-item-label')).length -4
        //let txtCount=await document.getElementsByClassName(".MuiCollapse-entered").getElementsByTagName("li").length;
        console.log(a)
        console.log(count)
        if(count > 1){
            for(let i=count;i>0;i--){
                await this.favoriteFolder.click()
                await this.deleteIcon.click()
                await this.deleteFolderButton.click()
                console.log('*******')
            }
        }

    }

 

posted @ 2023-01-12 14:04  陈晓猛  阅读(69)  评论(0编辑  收藏  举报