Skip to content

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

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

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

Conversation

@dgozman

@dgozman 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
@dgozman
dgozman force-pushed the locator-wait-for-function branch from 1d8c278 to 2dd6de9 Compare June 23, 2026 09:56
@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
@dgozman
dgozman force-pushed the locator-wait-for-function branch from 2dd6de9 to 9c5f7e3 Compare June 23, 2026 12:02
@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.

@dgozman
dgozman merged commit b5a45d9 into microsoft:main Jun 23, 2026
47 of 48 checks passed
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