Skip to main content
Version: 23.2.0

Page.tap() 方法

¥Page.tap() method

此方法使用 selector 获取元素,如果需要,将其滚动到视图中,然后使用 Page.touchscreen 点击元素的中心。如果没有与 selector 匹配的元素,该方法将抛出错误。

¥This method fetches an element with selector, scrolls it into view if needed, and then uses Page.touchscreen to tap in the center of the element. If there's no element matching selector, the method throws an error.

签名

¥Signature

class Page {
tap(selector: string): Promise<void>;
}

参数

¥Parameters

范围

类型

描述

selector

string

要查询页面的 selectorCSS 选择器 可以按原样传递,Puppeteer 特定的选择器语法 允许通过 texta11y 角色和名称xpath跨影子根组合这些查询 进行查询。或者,你可以使用 prefix 指定选择器类型。如果有多个元素满足选择器,则将点击第一个元素。

Returns:

Promise<void>

备注

¥Remarks

page.mainFrame().tap(selector) 的快捷方式。

¥Shortcut for page.mainFrame().tap(selector).