Search code examples
javascriptend-to-endcodeceptjs

How to know how many elements are on a page using codeceptjs


In Codeceptjs, I don't find a way to count the number a certain element is present on the page. The I.assertNumber in the example is some kind of made up clause to hopefully express better what I am looking for.

Scenario('test something', (I) => {
    I.amOnPage('http://example.com`);
    I.assertNumber((locate('div.someclass'),20); 
    .. }

Solution

  • You can use seeNumberOfElements or seeNumberOfVisibleElements methods

    see in docs (maybe you use other helper(Puppeteer, Protractor, etc), so see in its doc) https://codecept.io/helpers/WebDriver/#seenumberofelements https://codecept.io/helpers/WebDriver/#seenumberofvisibleelements