Keyboard.type() 方法
¥Keyboard.type() method
为文本中的每个字符发送 keydown、keypress/input 和 keyup 事件。
¥Sends a keydown, keypress/input, and keyup event for each character in the text.
签名
¥Signature
class Keyboard {
abstract type(
text: string,
options?: Readonly<KeyboardTypeOptions>,
): Promise<void>;
}
参数
¥Parameters
范围 | 类型 | 描述 |
|---|---|---|
text | string | 要输入到焦点元素中的文本。 |
options | (可选的)选项的对象。接受延迟,如果指定,则为 |
Returns:
Promise<void>
备注
¥Remarks
要按特殊键,例如 Control 或 ArrowDown,请使用 Keyboard.press()。
¥To press a special key, like Control or ArrowDown, use Keyboard.press().
修改键不会影响 keyboard.type。按住 Shift 将不会键入大写文本。
¥Modifier keys DO NOT effect keyboard.type. Holding down Shift will not type the text in upper case.
示例
¥Example
await page.keyboard.type('Hello'); // Types instantly
await page.keyboard.type('World', {delay: 100}); // Types slower, like a user