Skip to main content
Version: 24.38.0

ElementHandle.screenshot() 方法

🌐 ElementHandle.screenshot() method

screenshot(): Promise<string>

如果需要,此方法会将元素滚动到可视区域,然后使用 Page.screenshot() 对元素进行截图。如果元素已从 DOM 中分离,该方法会抛出错误。

🌐 This method scrolls element into view if needed, and then uses Page.screenshot() to take a screenshot of the element. If the element is detached from DOM, the method throws an error.

语法

🌐 Signature

class ElementHandle {
screenshot(
options: Readonly<ScreenshotOptions> & {
encoding: 'base64';
},
): Promise<string>;
}

参数

🌐 Parameters

范围

🌐 Parameter

类型

🌐 Type

描述

🌐 Description

options

Readonly<ScreenshotOptions> & { encoding: 'base64'; }

返回:

Promise<string>

screenshot(): Promise<Uint8Array>

语法

🌐 Signature

class ElementHandle {
screenshot(options?: Readonly<ScreenshotOptions>): Promise<Uint8Array>;
}

参数

🌐 Parameters

范围

🌐 Parameter

类型

🌐 Type

描述

🌐 Description

options

Readonly<ScreenshotOptions>

(可选)

🌐 (Optional)

返回:

Promise<Uint8Array>