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.
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.
Share Improve this question edited Oct 20, 2019 at 6:30 aitchkhan asked Oct 19, 2019 at 13:04 aitchkhanaitchkhan 1,9521 gold badge20 silver badges39 bronze badges1 Answer
Reset to default 9This was rather too easy.
cy.get(`ul`)
.get('li:contains(14 May, 2018)')
.should('have.length', 3);