🔠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.
Checking or asserting on the value of any element is straightforward in Playwright
Learn how to check whether an element exists or is visible 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
Explore 9 essential Playwright best practices to enhance the reliability, efficiency, and effectiveness of your end-to-end tests
Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.
Write for usWrite a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.
community@betterstack.comor submit a pull request and help us build better products for everyone.
See the full list of amazing projects on github