Reputation: 1952
Is there a way to get the number of occurrences of a certain text in an unordered list without using any Javascript in Cypress
?
I have something like this:
<ul>
<li>
14 May, 2018
</li>
<li>
14 May, 2018
</li>
<li>
23 Aug, 2018
</li>
<li>
14 May, 2018
</li>
</ul>
I want to count the occurrences of 14 May, 2018
. I can not use contain()
as it would only get the first element.
I did not find anything in the docs.
Upvotes: 4
Views: 2825
Reputation: 1952
This was rather too easy.
cy.get(`ul`)
.get('li:contains(14 May, 2018)')
.should('have.length', 3);
Upvotes: 9