Reputation: 149
Hi I want to count the number of buttons inside a specific tag How can I print the sum of buttons?
I tried
cy.log(cy.get('dropdown').find('button').count())
But it doesn't work
Upvotes: 1
Views: 1050
Reputation:
You can save the count with an alias
cy.get('dropdown').find('button').its('length').as('buttonCount')
... // more actions e.g add a button
cy.get('@buttonCount').then(previousCount => {
cy.get('dropdown').find('button').its('length')
.should('be.gt', previousCount)
})
Upvotes: 1
Reputation: 18624
You can get the length by using .its:
cy.get('dropdown').find('button').its('length').should('eq', 4)
Or, You can also get the length like:
cy.get('dropdown').find('button').its('length').then((len) => {
cy.log('No. of buttons are: ' + len)
})
Upvotes: 2