Skip to content

Commit 7e2fc26

Browse files
[docs]: add docs for .keyPress() (#1974)
# why - docs for `page.keyPress()` were missing # what changed <img width="730" height="727" alt="Screenshot 2026-04-07 at 1 41 38 PM" src="https://github.com/user-attachments/assets/1bf50de3-93b6-4fca-b632-cdb80bcfc3da" /> <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Added docs for `page.keyPress()` in the v3 Page reference. Includes the method signature, supported keys and modifier combos, the `delay` option, and examples for single keys and combinations (Enter, Cmd+A, ArrowDown, Ctrl+C, with delay). <sup>Written for commit 0cbf3a9. Summary will update on new commits. <a href="https://cubic.dev/pr/browserbase/stagehand/pull/1974">Review in cubic</a></sup> <!-- End of auto-generated description by cubic. -->
1 parent 7fe0fe4 commit 7e2fc26

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

packages/docs/v3/references/page.mdx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,32 @@ await page.type(text: string, options?: TypeOptions): Promise<void>
342342
</Expandable>
343343
</ParamField>
344344
345+
### keyPress()
346+
347+
Press a single key or key combination (keyDown then keyUp). Supports named keys, printable characters, and modifier combinations.
348+
349+
```typescript
350+
await page.keyPress(key: string, options?: KeyPressOptions): Promise<void>
351+
```
352+
353+
<ParamField path="key" type="string" required>
354+
The key or key combination to press. Supports printable characters (`"a"`, `"1"`), named keys (`"Enter"`, `"Tab"`, `"Escape"`, `"Backspace"`, `"ArrowDown"`, etc.), and modifier combinations using `+` (`"Cmd+A"`, `"Ctrl+C"`, `"Shift+Tab"`).
355+
356+
Common modifier aliases like `"Cmd"`, `"Ctrl"`, `"Alt"`, and `"Option"` are accepted. `"Cmd"` maps to Meta on Mac and Control elsewhere.
357+
</ParamField>
358+
359+
<ParamField path="options" type="object" optional>
360+
Optional key press configuration.
361+
362+
<Expandable title="properties">
363+
<ParamField path="delay" type="number">
364+
Delay in milliseconds between the keyDown and keyUp events.
365+
366+
Default: `0`
367+
</ParamField>
368+
</Expandable>
369+
</ParamField>
370+
345371
### locator()
346372
347373
Create a locator for querying elements.
@@ -886,6 +912,21 @@ await page.type("Hello, World!");
886912
// Type with delay between keystrokes
887913
await page.type("Slow typing", { delay: 100 });
888914

915+
// Press a single key
916+
await page.keyPress("Enter");
917+
918+
// Press a key combination (select all)
919+
await page.keyPress("Cmd+A");
920+
921+
// Press with delay between keyDown and keyUp
922+
await page.keyPress("Escape", { delay: 100 });
923+
924+
// Arrow key navigation
925+
await page.keyPress("ArrowDown");
926+
927+
// Copy selection
928+
await page.keyPress("Ctrl+C");
929+
889930
// Use locator for element interaction
890931
const button = page.locator("button.submit");
891932
await button.click();

0 commit comments

Comments
 (0)