我怎样才能收到元素的数量?
How can I receive count of elements?
test.js:
cy.get('.ant-input-number-input')
.wait(2000)
.then(($input_field) => {
const count = $input_field.find('.ant-input-number-input').length;
cy.log(count)
})
cy.log:
log 0
我需要计算元素的数量。但我收到了“0”。如何接收元素计数?
您可以使用
const count = $input_field.find('.ant-input-number-input').its('length')
假设你只求元素.ant-input-number-input
的长度,你可以这样做:
- 获取长度
cy.get('.ant-input-number-input')
.should('be.visible')
.its('length')
.then((len) => {
cy.log(len) //prints length
})
- 如果你想添加断言,你可以这样做:
//Length equal to 2
cy.get('.ant-input-number-input')
.should('be.visible')
.its('length')
.should('eq', 2)
//Length greater than 2
cy.get('.ant-input-number-input')
.should('be.visible')
.its('length')
.should('be.gt', 2)
//Length greater than or equal to 2
cy.get('.ant-input-number-input')
.should('be.visible')
.its('length')
.should('be.gte', 2)
//Length less than 2
cy.get('.ant-input-number-input')
.should('be.visible')
.its('length')
.should('be.lt', 2)
//Length less than or equal to 2
cy.get('.ant-input-number-input')
.should('be.visible')
.its('length')
.should('be.lte', 2)
test.js:
cy.get('.ant-input-number-input')
.wait(2000)
.then(($input_field) => {
const count = $input_field.find('.ant-input-number-input').length;
cy.log(count)
})
cy.log:
log 0
我需要计算元素的数量。但我收到了“0”。如何接收元素计数?
您可以使用
const count = $input_field.find('.ant-input-number-input').its('length')
假设你只求元素.ant-input-number-input
的长度,你可以这样做:
- 获取长度
cy.get('.ant-input-number-input')
.should('be.visible')
.its('length')
.then((len) => {
cy.log(len) //prints length
})
- 如果你想添加断言,你可以这样做:
//Length equal to 2
cy.get('.ant-input-number-input')
.should('be.visible')
.its('length')
.should('eq', 2)
//Length greater than 2
cy.get('.ant-input-number-input')
.should('be.visible')
.its('length')
.should('be.gt', 2)
//Length greater than or equal to 2
cy.get('.ant-input-number-input')
.should('be.visible')
.its('length')
.should('be.gte', 2)
//Length less than 2
cy.get('.ant-input-number-input')
.should('be.visible')
.its('length')
.should('be.lt', 2)
//Length less than or equal to 2
cy.get('.ant-input-number-input')
.should('be.visible')
.its('length')
.should('be.lte', 2)