Class JSHandleImpl

All Implemented Interfaces:
JSHandle
Direct Known Subclasses:
ElementHandleImpl

public class JSHandleImpl extends ChannelOwner implements JSHandle
  • Field Details

    • preview

      private String preview
  • Constructor Details

    • JSHandleImpl

      public JSHandleImpl(ChannelOwner parent, String type, String guid, com.google.gson.JsonObject initializer)
  • Method Details

    • asElement

      public ElementHandle asElement()
      Description copied from interface: JSHandle
      Returns either null or the object handle itself, if the object handle is an instance of ElementHandle.
      Specified by:
      asElement in interface JSHandle
    • dispose

      public void dispose()
      Description copied from interface: JSHandle
      The jsHandle.dispose method stops referencing the element handle.
      Specified by:
      dispose in interface JSHandle
    • evaluate

      public Object evaluate(String pageFunction, Object arg)
      Description copied from interface: JSHandle
      Returns the return value of expression.

      This method passes this handle as the first argument to expression.

      If expression returns a Promise, then handle.evaluate would wait for the promise to resolve and return its value.

      **Usage**

      
       ElementHandle tweetHandle = page.querySelector(".tweet .retweets");
       assertEquals("10 retweets", tweetHandle.evaluate("node => node.innerText"));
       
      Specified by:
      evaluate in interface JSHandle
      Parameters:
      pageFunction - JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is automatically invoked.
      arg - Optional argument to pass to expression.
    • evaluateHandle

      public JSHandle evaluateHandle(String pageFunction, Object arg)
      Description copied from interface: JSHandle
      Returns the return value of expression as a JSHandle.

      This method passes this handle as the first argument to expression.

      The only difference between jsHandle.evaluate and jsHandle.evaluateHandle is that jsHandle.evaluateHandle returns JSHandle.

      If the function passed to the jsHandle.evaluateHandle returns a Promise, then jsHandle.evaluateHandle would wait for the promise to resolve and return its value.

      See Page.evaluateHandle() for more details.

      Specified by:
      evaluateHandle in interface JSHandle
      Parameters:
      pageFunction - JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is automatically invoked.
      arg - Optional argument to pass to expression.
    • getProperties

      public Map<String,JSHandle> getProperties()
      Description copied from interface: JSHandle
      The method returns a map with **own property names** as keys and JSHandle instances for the property values.

      **Usage**

      
       JSHandle handle = page.evaluateHandle("() => ({ window, document })");
       Map<String, JSHandle> properties = handle.getProperties();
       JSHandle windowHandle = properties.get("window");
       JSHandle documentHandle = properties.get("document");
       handle.dispose();
       
      Specified by:
      getProperties in interface JSHandle
    • getProperty

      public JSHandle getProperty(String propertyName)
      Description copied from interface: JSHandle
      Fetches a single property from the referenced object.
      Specified by:
      getProperty in interface JSHandle
      Parameters:
      propertyName - property to get
    • jsonValue

      public Object jsonValue()
      Description copied from interface: JSHandle
      Returns a JSON representation of the object. If the object has a toJSON function, it **will not be called**.

      NOTE: The method will return an empty JSON object if the referenced object is not stringifiable. It will throw an error if the object has circular references.

      Specified by:
      jsonValue in interface JSHandle
    • handleEvent

      void handleEvent(String event, com.google.gson.JsonObject parameters)
      Overrides:
      handleEvent in class ChannelOwner
    • toString

      public String toString()
      Overrides:
      toString in class Object