Html:
<tbody class="ant-table-tbody">
<tr class="ant-table-row"> 1 </tr>
<tr class="ant-table-row"> 2 </tr>
...
<tr class="ant-table-row"> n </tr>
</tbody>
JS:
let count = cy.get('.ant-table-tbody').find('.ant-table-row')
if (count >= 0) {
cy.log(`There are ${count} elements`)
} else {
cy.log('There are no elements')
}
当我得到.ant-table-tbody
我需要计算的元素.ant-table-row
元素。如果计数超过 '0' cy.log 元素计数,如果为 '0' 元素应 cy.log - 无元素。
我该怎么做?
好吧,我想你想知道什么时候有零行以及 > 0,所以
cy.get('.ant-table-tbody')
.then($tbody => {
const count = $tbody.find('.ant-table-row').length // jquery find won't fail
if (count > 0) {
cy.log(`There are ${count} elements`)
} else {
cy.log('There are no elements')
}
})
如果零行不可能,其他答案更简单。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)