🔠Want to automate and scale your Playwright end-to-end tests?
Head over to Better Stack and start monitoring in 5 minutes.
In most cases, you'll be writing tests that performs an action on one element at a time. However, if you need to perform an action on multiple elements at once (such as clicking on several items in a list), you can do it as follows:
test('user can click multiple list items', async ({ page }) => {
const items = page.locator('ul > li');
for (let i = 0; i < await items.count(); i++) {
await items.nth(i).click();
}
})
Once you've selected all the items using the appropriate locator method, you can iterate over the found items using and then perform the relevant action in the body of the loop.
Thanks for reading, and happy coding!
Head over to Better Stack and start monitoring in 5 minutes.
Explore 9 essential Playwright best practices to enhance the reliability, efficiency, and effectiveness of your end-to-end tests
Learn how to check whether an element exists or is visible in Playwright
Checking or asserting on the value of any element is straightforward in Playwright
Learn to learn to develop and execute Playwright test scripts, utilize its time travel debugging capabilities, and proactively identify visual regressions in this hands-on guide