How to get a no of web elements using codeceptJS

Hi All

Iam new to codeceptJS, I would like to know how can we get List of webelements using codeceptJS like we havein selenium webDriver
List anchorElements = driver.findByelements(By.xpath(‘locatorid’));
The above statement returns list of elements , then we can get the count, and iterate through all elments using for loop or forEach element, then we can click on each element or get text, get attribute value from each element.

Now , The same scenario I would like to do with codeCeptJS
I used I.grabNumberOfVisibleElements(‘locatorid > div’), it is retirnung : 0 always

Eventhough I have 10 elements, I used same locator in ChroPath, it is showing 10 elements too. but Codecept giving “0” and test ends

Please let me know the alternative how can get list of webelements & webelemnts count using codeceptJS

When using any grab actions with codeceptJS you need to keep in mind that they run async.
Therefore to receive the value from the action you need to await it

const noOfElements = await I.grabNumberOfVisibleElements('p');

yes I used await

let numOfElements = await I.grabNumberOfVisibleElements({xpath: ‘//ul[@class=“classname”]/li’});

above statement is giving 0;

I checked woth another element which had id like
let numOfElements = await I.grabNumberOfVisibleElements(#idofelement); ==> then it give 1

I used await like below:

let numOfElements = await I.grabNumberOfVisibleElements({xpath: ‘//ul[@class=“classname”]/li’});

above statement is giving 0;

I checked with another element which had id like
let numOfElements = await I.grabNumberOfVisibleElements(#idofelement); ==> then it give 1

I found solution for this using i.grabAttributeFromAll & I.grabTextFromALL

As I found the problem myself that grabNumberOfVisibleElements() returns 0

I just tried putting a small wait before the grabbing. E.g.

await I.wait(2);
await I.grabNumberOfVisibleElements(
      'select[id="idOfDropdown"] > option',
    );

That worked for me.

Hi All, Test execution fails at GrabText and grabVisibleElements both in headless mode. Any suggestions pls?