Cypress: How to get <li> only without its children <li>?
I'm recently using cypress and I want to get the array of list but I just want the to get <li>
under the class "list" and not including the other children of <li>
I'm using
cy.get('.list >li')
but I'm also getting the children <li>
under Home.
<ul class="list">
<li>Home</li>
<ul>
<li>Another One</li>
<li>Another Two</li>
</ul>
<li>Page</li>
<li>Hello</li>
<li>Hi</li>
</ul>
you have two ways to do this
-
get only li children of parent
cy.get('.list').children('li')
-
get children by level in dom
cy.get('.list > li') .its('length') .should('eq', 2)