最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get occurrences of text in cypress test - Stack Overflow

programmeradmin1浏览0评论

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 badges
Add a ment  | 

1 Answer 1

Reset to default 9

This was rather too easy.

cy.get(`ul`)
   .get('li:contains(14 May, 2018)')
   .should('have.length', 3);
发布评论

评论列表(0)

  1. 暂无评论