Skip to main content
Version: 22.9.0

Page.$() 方法

¥Page.$() method

在页面内运行 document.querySelector。如果没有元素与选择器匹配,则返回值解析为 null

¥Runs document.querySelector within the page. If no element matches the selector, the return value resolves to null.

签名:

¥Signature:

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

参数

¥Parameters

范围

类型

描述

selector

选择器

selector 查询页面,selector 查询页面。

Returns:

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