Page locators are the better way to select elements in Playwright



AI Summary

This video tutorial explains the difference between element handles and locators in Playwright, a testing framework for web applications. It demonstrates testing a demo site with a button that adds images on click. Using element handles (page.), the test fails on repeated clicks because the references to DOM elements do not update automatically.

The video then presents the better approach of using page locators, which are lazy and evaluate DOM elements fresh each time they are accessed. This enables more reliable assertions and interactions in tests, as the locators always reflect the current state of the DOM. The speaker encourages using page locators over element handles for cleaner and more robust Playwright test scripts.