Skip to content

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

Open
dgozman wants to merge 1 commit into
microsoft:mainfrom
dgozman:locator-wait-for-function
Open

feat(locator): introduce Locator.waitForFunction()#41380
dgozman wants to merge 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'));

References #41317

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.

Closes microsoft#41317
@github-actions

Copy link
Copy Markdown
Contributor

Test results for "MCP"

1 failed
❌ [chromium] › mcp/cli-parsing.spec.ts:47 › arg after boolean option @mcp-macos-latest-chromium

7353 passed, 1122 skipped


Merge workflow run.

@github-actions

Copy link
Copy Markdown
Contributor

Test results for "tests 1"

2 failed
❌ [firefox-page] › page/workers.spec.ts:40 › should emit created and destroyed events @firefox-ubuntu-22.04-node20
❌ [playwright-test] › reporter-html.spec.ts:307 › created › should not include image diff with non-images @ubuntu-latest-node20

3 flaky ⚠️ [chromium-library] › library/video.spec.ts:337 › screencast › should work for popups `@chromium-ubuntu-22.04-arm-node20`
⚠️ [firefox-library] › library/inspector/cli-codegen-3.spec.ts:224 › cli codegen › should generate frame locators (4) `@firefox-ubuntu-22.04-node20`
⚠️ [webkit-page] › page/page-set-input-files.spec.ts:38 › should upload a folder `@webkit-ubuntu-22.04-node20`

39705 passed, 750 skipped


Merge workflow run.

async waitForFunction<R, Arg>(pageFunction: structs.PageFunctionOn<SVGElement | HTMLElement, Arg, R>, arg?: Arg, options?: TimeoutOptions): Promise<void> {
await this._frame._channel.waitForFunction({
selector: this._selector,
strict: true,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be configurable?

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