Skip to content

feat(keyboard): add array overload to pressSequentially#40748

Open
SebTardif wants to merge 3 commits into
microsoft:mainfrom
SebTardif:feat/press-sequentially-array
Open

feat(keyboard): add array overload to pressSequentially#40748
SebTardif wants to merge 3 commits into
microsoft:mainfrom
SebTardif:feat/press-sequentially-array

Conversation

@SebTardif
Copy link
Copy Markdown
Contributor

Summary

  • Adds string[] overload to Locator.pressSequentially so it can accept an array of key names in addition to a string of characters
  • Adds new Keyboard.pressSequentially method mirroring the same behavior
  • When given an array, each element is treated as a key name (same format as keyboard.press()) and pressed sequentially with optional delay between presses

Usage:

// Existing string behavior
await locator.pressSequentially('Hello');

// New array overload
await locator.pressSequentially(['Control+A', 'Delete', 'H', 'e', 'l', 'l', 'o']);

// Also available on Keyboard
await page.keyboard.pressSequentially(['Control+A', 'Delete']);

Fixes #40740

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Comment thread docs/src/api/class-frame.md Outdated
### option: Frame.press.timeout = %%-input-timeout-js-%%
* since: v1.8

## async method: Frame.pressSequentially
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's not introduce a discouraged method 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, removed.

Comment thread docs/src/api/class-locator.md Outdated
- `text` <[string]|[Array]<[string]>>

String of characters to sequentially press into a focused element.
String of characters to sequentially press into a focused element, or an array of key names to press sequentially. Key names follow the same format as [`method: Locator.press`].
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

How about we support the following notation: Hello{ArrowRight}{Ctrl+A}world!{Backspace}? Basically, treating anything inside {} as a key from the press method, when passed a namedKeys: true option.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reworked. Added namedKeys: true option to Locator.pressSequentially and Keyboard.type. {KeyName} treats brace content as a key name for press(), with {{/}} for literal braces.

await locator.pressSequentially('Hello{Enter}World', { namedKeys: true });
await locator.pressSequentially('{Control+A}{Delete}Hello', { namedKeys: true });
await locator.pressSequentially('type {{braces}}', { namedKeys: true }); // types: type {braces}

SebTardif added 3 commits May 11, 2026 17:01
Add string[] overload to Locator.pressSequentially and new
Keyboard.pressSequentially method, as requested in microsoft#40740.

When given an array, each element is treated as a key name
(same format as keyboard.press()) and pressed sequentially
with optional delay between presses.

Fixes microsoft#40740
Add missing documentation for Frame.pressSequentially selector-based
method to fix doclint CI failure.

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
Rework pressSequentially based on review feedback:
- Drop Frame.pressSequentially (no new discouraged methods)
- Drop Keyboard.pressSequentially and keyboardPressSequentially protocol
- Add namedKeys option to Locator.pressSequentially and Keyboard.type
- {KeyName} syntax treats braces content as key names for press()
- {{ and }} escape to literal brace characters

Fixes: microsoft#40740
@SebTardif SebTardif force-pushed the feat/press-sequentially-array branch from aec15c9 to 4375b42 Compare May 12, 2026 00:07
@github-actions
Copy link
Copy Markdown
Contributor

Test results for "MCP"

1 failed
❌ [webkit] › mcp/cli-test.spec.ts:23 › debug test and snapshot @mcp-windows-latest-webkit

7069 passed, 1068 skipped


Merge workflow run.

@github-actions
Copy link
Copy Markdown
Contributor

Test results for "tests 1"

2 flaky ⚠️ [chromium-library] › library/video.spec.ts:719 › screencast › should work with video+trace `@ubuntu-22.04-chromium-tip-of-tree`
⚠️ [webkit-library] › library/browsertype-connect.spec.ts:792 › run-server › should upload a folder `@webkit-ubuntu-22.04-node20`

40747 passed, 845 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.

[Feature]: keyboard.pressSequence() for batched named key presses

3 participants