Skip to main content
Version: 23.2.0

ElementHandle.$() 方法

¥ElementHandle.$() method

查询当前元素以查找与给定选择器匹配的元素。

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

签名

¥Signature

class ElementHandle {
$<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.