使用 mocha 测试框架计算元素的 div

Counting element's div's by using mocha testing framework

我使用 xpath 获取了一个 WebElement JSON 对象,这个项目是一个 div,里面有 div。

it('Count terminals in view', function() {
    elems = browser.elements('/html/body/div[2]/ui-view/div/div[1]/div[4]/div[2]');
    console.log(elems.value);
});

html 代码如下所示

<div class="col-lg-8 col-md-pull-0 col-lg-pull-4">
    <div class="col-lg-12">
        <div style="margin: 10px 0px 10px 0px;">
            <div class="row">
                <div class="col-lg-4">
                    <div>Hardware Id</div>
                    <div ng-bind="terminal.hardwareId" style=" cursor: pointer; width: 100%" ng-click="downloadVM.openModal(terminal.hardwareId);" class="ng-binding">S8EVMOC00019</div>
                </div>
            </div>
        </div>
    </div>              

    <div class="col-lg-12">
        <div style="margin: 10px 0px 10px 0px;">
            <div class="row">
                <div class="col-lg-4">
                    <div>Hardware Id</div>
                    <div ng-bind="terminal.hardwareId" style=" cursor: pointer; width: 100%" ng-click="downloadVM.openModal(terminal.hardwareId);" class="ng-binding">S8NOMOT00049</div>
                </div>
            </div>
        </div>
    </div>              
</div>

我需要能够计算出它们是可变的 hardwareId,我怎样才能正确地遍历它们?

找到了对 div 进行计数的方法,只是在顶部添加了一个通配符“*”div,然后循环计数变量。

count = browser.elements('/html/body/div[2]/ui-view/div/div[1]/div[4]/div[2]/*');
console.log(count);
for (el in count.value) {
    console.log(el); 
}