Keyboard.type() 方法
針對文字中的每個字元,發送 keydown
、keypress
/input
和 keyup
事件。
簽名
class Keyboard {
abstract type(
text: string,
options?: Readonly<KeyboardTypeOptions>,
): Promise<void>;
}
參數
參數 | 類型 | 描述 |
---|---|---|
text | string | 要輸入到焦點元素中的文字。 |
options | Readonly<KeyboardTypeOptions> | (選用)選項的物件。接受 delay,如果指定,則為 |
回傳
Promise<void>
備註
若要按下特殊按鍵,例如 Control
或 ArrowDown
,請使用 Keyboard.press()。
修飾鍵不會影響 keyboard.type
。按住 Shift
不會輸入大寫文字。
範例
await page.keyboard.type('Hello'); // Types instantly
await page.keyboard.type('World', {delay: 100}); // Types slower, like a user