class Playwright::Page

def add_locator_handler(locator, handler)

```
page.get_by_role("button", name="Start here").click()
page.goto("https://example.com")
# Write the test as usual.

page.add_locator_handler(page.locator("body"), handler)
page.evaluate("window.removeObstructionsForTestIfNeeded()")
def handler():
# Setup the handler.
```python sync

An example with a custom callback on every actionability check. It uses a `` locator that is always visible, so the handler is called before every actionability check:

```
page.get_by_role("button", name="Start here").click()
page.goto("https://example.com")
# Write the test as usual.

page.add_locator_handler(page.get_by_text("Confirm your security details"), handler)
page.get_by_role("button", name="Remind me later").click()
def handler():
# Setup the handler.
```python sync

An example that skips the "Confirm your security details" page when it is shown:

```
page.get_by_role("button", name="Start here").click()
page.goto("https://example.com")
# Write the test as usual.

page.add_locator_handler(page.get_by_role("button", name="Accept all cookies"), handler)
page.get_by_role("button", name="Reject all cookies").click()
def handler():
# Setup the handler.
```python sync

An example that closes a cookie dialog when it appears:

**Usage**

Another example is a series of mouse actions, where [`method: Mouse.move`] is followed by [`method: Mouse.down`]. Again, when the handler runs between these two actions, the mouse position will be wrong during the mouse down. Prefer methods like [`method: Locator.click`] that are self-contained.




For example, consider a test that calls [`method: Locator.focus`] followed by [`method: Keyboard.press`]. If your handler clicks a button between these two actions, the focused element most likely will be wrong, and key press will happen on the unexpected element. Use [`method: Locator.press`] instead to avoid this problem.




**NOTE**: Running the interceptor will alter your page state mid-test. For example it will change the currently focused element and move the mouse. Make sure that the actions that run after the interceptor are self-contained and do not rely on the focus and mouse state.

You can register multiple handlers. However, only a single handler will be running at a time. Any actions inside a handler must not require another handler to run.

Note that execution time of the handler counts towards the timeout of the action/assertion that executed the handler.

This method registers a handler for an overlay that is executed once the locator is visible on the page. The handler should get rid of the overlay so that actions blocked by it can proceed. This is useful for nondeterministic interstitial pages or dialogs, like a cookie consent dialog.

Sometimes, the web page can show an overlay that obstructs elements behind it and prevents certain actions, like click, from completing. When such an overlay is shown predictably, we recommend dismissing it as a part of your test flow. However, sometimes such an overlay may appear non-deterministically, for example certain cookies consent dialogs behave this way. In this case, [`method: Page.addLocatorHandler`] allows handling an overlay during an action that it would block.
def add_locator_handler(locator, handler)
  raise NotImplementedError.new('add_locator_handler is not implemented yet.')
end