Skip to main content
Version: 23.2.0

ElementHandle.press() 方法

¥ElementHandle.press() method

聚焦元素,然后使用 Keyboard.down()Keyboard.up()

¥Focuses the element, and then uses Keyboard.down() and Keyboard.up().

签名

¥Signature

class ElementHandle {
press(key: KeyInput, options?: Readonly<KeyPressOptions>): Promise<void>;
}

参数

¥Parameters

范围

类型

描述

key

KeyInput

要按下的键的名称,例如 ArrowLeft。有关所有键名称的列表,请参阅 KeyInput

options

只读<KeyPressOptions>

(可选的)

Returns:

Promise<void>

备注

¥Remarks

如果 key 是单个字符,并且除了 Shift 之外没有按下修饰键,则还将生成 keypress/input 事件。可以指定 text 选项来强制生成输入事件。

¥If key is a single character and no modifier keys besides Shift are being held down, a keypress/input event will also be generated. The text option can be specified to force an input event to be generated.

注意修饰键确实会影响 elementHandle.press。按住 Shift 将以大写形式键入文本。

¥NOTE Modifier keys DO affect elementHandle.press. Holding down Shift will type the text in upper case.