Skip to main content
Version: 22.14.0

Frame.$()方法

¥Frame.$() method

查询框架中与给定选择器匹配的元素。

¥Queries the frame for an element matching the given selector.

签名:

¥Signature:

class Frame {
$<Selector extends string>(
selector: Selector
): Promise<ElementHandle<NodeFor<Selector>> | null>;
}

参数

¥Parameters

范围

类型

描述

selector

选择器

要查询页面的 selectorCSS 选择器 可以按原样传递,Puppeteer 特定的选择器语法 允许通过 texta11y 角色和名称xpath跨影子根组合这些查询 进行查询。或者,你可以使用 prefix 指定选择器类型。

Returns:

Promise<ElementHandle<NodeFor<Selector>> | null>

元素句柄 到与给定选择器匹配的第一个元素。否则,null

¥A element handle to the first element matching the given selector. Otherwise, null.