Skip to content

feat(locator): introduce Locator.waitForFunction() - #41380

Merged
Dmitry Gozman (dgozman) merged 1 commit into
microsoft:mainfrom
dgozman:locator-wait-for-function
Jun 23, 2026
Merged

feat(locator): introduce Locator.waitForFunction()#41380
Dmitry Gozman (dgozman) merged 1 commit into
microsoft:mainfrom
dgozman:locator-wait-for-function

Conversation

@dgozman

@dgozman Dmitry Gozman (dgozman) commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds Locator.waitForFunction(pageFunction, arg?, options?) — waits until the predicate, called with the matching element as its first argument, returns a truthy value.
  • The locator is re-resolved on every poll, so it tolerates the element being re-rendered. Intended for synchronization inside helpers, without asserting.
  • Implemented by extending the existing Frame.waitForFunction machinery with an optional selector; no new protocol method.
await toggle.waitForFunction(element => element.hasAttribute('aria-expanded'));

Drive-by: fixes wrong type overrides for Locator.

References #41317

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Comment thread packages/playwright-core/src/client/locator.ts
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Waits until a predicate, called with the matching element as its first
argument, returns a truthy value. The locator is re-resolved on every
poll, so it tolerates the element being re-rendered. Useful for
synchronization inside helpers without asserting.

Drive-by: fixes wrong type overrides for Locator.

Closes microsoft#41317
@github-actions

Copy link
Copy Markdown
Contributor

Test results for "MCP"

7380 passed, 1122 skipped


Merge workflow run.

@github-actions

Copy link
Copy Markdown
Contributor

Test results for "tests 1"

2 failed
❌ [chromium-library] › library/browsercontext-add-init-script.spec.ts:28 › should work without navigation, after all bindings @chromium-ubuntu-22.04-arm-node20
❌ [chromium-library] › library/browsercontext-expose-function.spec.ts:77 › should be callable from-inside addInitScript @chromium-ubuntu-22.04-arm-node20

3 flaky ⚠️ [chromium-page] › page/page-request-continue.spec.ts:756 › propagate headers cross origin redirect after interception `@frozen-time-library-chromium-linux`
⚠️ [chromium-library] › library/video.spec.ts:680 › screencast › should capture full viewport on hidpi `@chromium-ubuntu-22.04-node22`
⚠️ [firefox-library] › library/inspector/cli-codegen-3.spec.ts:224 › cli codegen › should generate frame locators (4) `@firefox-ubuntu-22.04-node20`

48999 passed, 1142 skipped


Merge workflow run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants