Skip to main content
Version: 23.5.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

范围

类型

描述

options

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

Returns:

Promise<string>

screenshot():Promise<Uint8Array>

签名

¥Signature

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

参数

¥Parameters

范围

类型

描述

options

只读<ScreenshotOptions>

(可选的)

Returns:

Promise<Uint8Array>