[feat]: add `getByPrompt()`

SE
18h ago
+3050-267

why

this pr adds getByPrompt() & get_by_prompt() so users can describe an element, then act on it using the existing locator actions

await page.locator("#settings").getByPrompt("save billing settings").click();
await page.locator("#settings").get_by_prompt("save billing settings").click()

what changed

  • added getByPrompt() on Page & Locator in typescript, plus get_by_prompt() in python. both return a dedicated PromptLocator supporting click, hover, fill, type, scroll, click-event dispatch, option selection, & file uploads.
  • construction stays lazy. each action resolves the preceding locator chain, offers eligible candidates to the decision callback, & acts on the selected element. filters & indices can narrow the scope before the prompt; an iframe prefix enters its child document. open & closed shadow roots are supported.
  • connected prompt requests to the existing target resolver & action implementations. the selected element retains its identity without automatic reselection. detected detachment or frame navigation fails validation; normal timing races remain between validation & browser input.
  • selection & execution share one deadline, with no automatic inference retry or action replay. no match, refusal, & provider failures remain separate outcomes. file contents are not sent as candidate evidence.
  • shared action serialization between ordinary & prompt locators preserves arguments, options, return values, & file handling. prompt locators do not expose reads, counts, filters, further chaining, or use as masks or ai-operation scopes. unsupported requests are also rejected at runtime

test plan

added & extended tests covering:

  • accepted action requests, invalid prompts, conflicting descriptor fields, unsupported operations, & python model validation.
  • lazy construction, independent prefixes, ordered queries/filters/indices, & argument serialization for all eight actions in both sdks.
  • action-only public types & runtime rejection of prompt locators as screenshot masks or ai-operation scopes.
  • configured decision callbacks through the public sdk & callback batches, including original choice ids & at-most-once action dispatch.
  • no match, refusal, missing configuration, provider failures, invalid answers, expired deadlines, late callbacks, & temporary handle cleanup.
  • real actions after element renaming or movement, rejection of targets detached before action validation, explicit same-origin/out-of-process iframe scopes, open/closed shadow roots, form values, & file uploads.
  • cross-language action parity, field forwarding through the shared action helpers, & public reference coverage.

Summary by cubic

Adds getByPrompt() in TypeScript and get_by_prompt() in Python so users can describe an element in natural language and then act on it with existing locator actions such as click() or fill().

  • Construction is lazy; invoking an action collects eligible candidates in scope and asks the configured decision callback to pick one before running the action.
  • Deterministic prefixes and iframe chains narrow candidate scope, with open and closed shadow roots included as candidates.
  • Selection and execution share one deadline with no retry; no match, refusal, and provider failures remain separate outcomes.
  • Prompt locators support click, hover, fill, type, scroll, click-event dispatch, option selection, and file uploads, but reject reads, counts, filters, further chaining, and use as masks or AI-operation scopes.

Requires a configured decision callback; unsupported requests are rejected at runtime.