How to count dom elemnts with Cypress?

Viewed 40

I would like to count the number of elements in the dom that are checked

Example :

cy.get('.p-multiselect-item .p-highlight').its('length');
2 Answers

You are using p-multiselect-item as a class (leading dot) but actually it's a tag.

Try

cy.get('p-multiselect-item .p-highlight')  // find <p-multiselect-item> 
                                           // with children having class p-highlight
  .its('length')
  .should('eq', 2)
Related