playwright.expect.expect_to_change

playwright.expect.expect_to_change(func, timeout_secs=10)

Context manager that yields when the value returned by func() changes.

Use this around code that has a side-effect of changing some state asynchronously (such as all browser actions), to prevent moving onto the next step of the test until this one has actually taken effect.

Parameters

Name Type Description Default
func Callable[[], Any] A function that returns a value. The value returned by this function is compared to the value returned by subsequent calls to this function. required
timeout_secs float How long to wait for the value to change before raising TimeoutError. 10

Raises

Name Type Description
TimeoutError If the value does not change within timeout_secs.

Example

with expect_to_change(lambda: page.locator("#name").value()):
    page.keyboard.send_keys("hello")