I am getting el is not a iterator in the for loop. Why is this? There is a successfull count of 15 elements
it('source patient column should light blue background', async({ page }) => {
const el = page.locator(".grid > div:nth-child(n+16):nth-child(-n+30)");
await expect(el).toHaveCount(15);
for (let item of el) {
await expect(item).toHaveCSS('background-color', '#cfebe3');
}
});
This thread is trying to answer question "Why is the user getting an error that the element is not iterable in the for loop?"
I tried all()
also
TypeError: page.locator.all is not a function or its return value is not iterable
87 |
88 | // to do -fix this
> 89 | for (let item of page.locator(".grid > div:nth-child(n+16):nth-child(-n+30)").all()) {
| ^
90 | await expect(item).toHaveCSS('background-color', '#cfebe3');
91 | }
92 | });
You need to await all(): https://playwright.dev/docs/locators#rare-use-cases
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].