Options
All
  • Public
  • Public/Protected
  • All
Menu

Represents an in-page DOM element. ElementHandles can be created with the page.$ method.

Type parameters

  • E: Element

Hierarchy

Index

Methods

$

  • The method runs element.querySelector within the page. If no element matches the selector, the return value resolve to null.

    since

    0.13.0

    Parameters

    • selector: string

      A selector to query element for

    Returns Promise<ElementHandle | null>

$$

  • The method runs element.querySelectorAll within the page. If no elements match the selector, the return value resolve to [].

    since

    0.13.0

    Parameters

    • selector: string

      A selector to query element for

    Returns Promise<ElementHandle[]>

$x

  • Parameters

    • expression: string

    Returns Promise<ElementHandle[]>

asElement

boundingBox

  • This method returns the value resolve to the bounding box of the element (relative to the main frame), or null if the element is not visible.

    Returns Promise<BoundingBox | null>

boxModel

  • This method returns boxes of the element, or null if the element is not visible. Boxes are represented as an array of points; each Point is an object {x, y}. Box points are sorted clock-wise.

    Returns Promise<BoxModel | null>

click

  • This method scrolls element into view if needed, and then uses page.mouse to click in the center of the element. If the element is detached from DOM, the method throws an error.

    since

    0.9.0

    Parameters

    Returns Promise<void>

contentFrame

  • contentFrame(): Promise<Frame | null>
  • since

    1.2.0

    Returns Promise<Frame | null>

    Resolves to the content frame for element handles referencing iframe nodes, or null otherwise.

dispose

  • dispose(): Promise<void>
  • Stops referencing the element handle.

    Returns Promise<void>

executionContext

  • executionContext(): any

focus

  • focus(): Promise<void>
  • Calls focus on the element.

    Returns Promise<void>

getProperties

  • getProperties(): Promise<Map<string, JSHandle>>
  • Returns a map with property names as keys and JSHandle instances for the property values.

    Returns Promise<Map<string, JSHandle>>

getProperty

  • getProperty(propertyName: string): Promise<JSHandle>
  • Fetches a single property from the objectHandle.

    Parameters

    • propertyName: string

      The property to get.

    Returns Promise<JSHandle>

hover

  • hover(): Promise<void>
  • This method scrolls element into view if needed, and then uses page.mouse to hover over the center of the element. If the element is detached from DOM, the method throws an error.

    Returns Promise<void>

isIntersectingViewport

  • isIntersectingViewport(): Promise<boolean>
  • Resolves to true if the element is visible in the current viewport.

    Returns Promise<boolean>

jsonValue

  • jsonValue(): Promise<any>
  • Returns a JSON representation of the object. The JSON is generated by running JSON.stringify on the object in page and consequent JSON.parse in puppeteer.

    throws

    The method will throw if the referenced object is not stringifiable.

    Returns Promise<any>

press

  • press(key: string, options?: { delay?: number; text?: string }): Promise<void>
  • Focuses the element, and then uses keyboard.down and keyboard.up.

    Parameters

    • key: string

      Name of key to press, such as ArrowLeft. See USKeyboardLayout for a list of all key names.

    • Optional options: { delay?: number; text?: string }

      The text and delay options.

      • Optional delay?: number
      • Optional text?: string

    Returns Promise<void>

screenshot

  • 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.

    Parameters

    Returns Promise<string>

tap

  • tap(): Promise<void>
  • This method scrolls element into view if needed, and then uses touchscreen.tap to tap in the center of the element. If the element is detached from DOM, the method throws an error.

    Returns Promise<void>

toString

  • toString(): string
  • Returns string

type

  • type(text: string, options?: { delay: number }): Promise<void>
  • Focuses the element, and then sends a keydown, keypress/input, and keyup event for each character in the text.

    Parameters

    • text: string

      A text to type into a focused element.

    • Optional options: { delay: number }

      The typing options.

      • delay: number

    Returns Promise<void>

uploadFile

  • uploadFile(...filePaths: string[]): Promise<void>
  • This method expects elementHandle to point to an input element.

    Parameters

    • Rest ...filePaths: string[]

      Sets the value of the file input these paths. If some of the filePaths are relative paths, then they are resolved relative to current working directory.

    Returns Promise<void>