Page.$() 方法
¥Page.$() method
查找与选择器匹配的第一个元素。如果没有元素与选择器匹配,则返回值解析为 null
。
¥Finds the first element that matches the selector. 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。CSS 选择器 可以按原样传递,Puppeteer 特定的选择器语法 允许通过 text、a11y 角色和名称、xpath 和 跨影子根组合这些查询 进行查询。或者,你可以使用 prefix 指定选择器类型。 |
Returns:
Promise<ElementHandle<NodeFor<Selector>> | null>
备注
¥Remarks
Page.mainFrame().$(selector) 的快捷方式。
¥Shortcut for Page.mainFrame().$(selector).