Locator
The Locator API makes it easier to work with dynamically changing elements. Some of the benefits of using it over existing ways to locate an element (e.g. Page.$()
) include:
- Helps with writing robust tests by finding an element even if the underlying frame navigates.
- Makes it easier to work with dynamic web pages and SPAs built with Svelte, React, Vue, etc.
- Enables the use of test abstractions like the Page Object Model (POM) pattern to simplify and organize tests.
strict
mode is enabled for alllocator
methods that are expected to target a single DOM element, meaning that if more than one element matches the given selector, an error will be thrown.
Locator can be created with the page.locator(selector[, options]) method.