Interface Element

All Superinterfaces:
EventTarget, Node, SearchContext
All Known Subinterfaces:
FormControlElement, FormElement, FrameElement, ImageElement, InputElement, OptionElement, SelectElement, TextAreaElement

public interface Element extends Node
An HTML DOM element.

All HTML element interfaces derive from this interface.

  • Method Details

    • attributes

      ElementAttributes attributes()
      Returns HTML attributes of this element.
      Throws:
      ObjectClosedException - when this instance is closed
    • innerHtml

      String innerHtml()
      Returns a string with the HTML content of this element, or an empty string if the element does not have inner HTML.
      Throws:
      ObjectClosedException - when this instance is closed
    • innerHtml

      boolean innerHtml(String html)
      Replaces the HTML content of this element with the given html.
      Parameters:
      html - a new HTML content of this element
      Returns:
      true when the HTML content of the element was successfully replaced
      Throws:
      ObjectClosedException - when this instance is closed
    • outerHtml

      String outerHtml()
      Returns a string with the HTML serialization of this element and its descendants.
      Throws:
      ObjectClosedException - when this instance is closed
      Since:
      7.1
    • outerHtml

      boolean outerHtml(String html)
      Replaces the element and all of its descendants with a new DOM tree constructed by parsing the given html.
      Parameters:
      html - a new HTML of this element
      Returns:
      true when the HTML of the element was successfully replaced
      Throws:
      ObjectClosedException - when this instance is closed
      Since:
      7.1
    • innerText

      String innerText()
      Returns a string with the text content of the element and its descendants. This method can return an empty string if the element does not have a content.
      Throws:
      ObjectClosedException - when this instance is closed
    • innerText

      boolean innerText(String innerText)
      Replaces the text content of the element with the given innerText value. Assigning a new value to the inner text will destroy any descendants of the element.
      Parameters:
      innerText - a new text content of the element
      Returns:
      true when the text content of the element was successfully replaced
      Throws:
      ObjectClosedException - when this instance is closed
    • boundingClientRect

      Rect boundingClientRect()
      Returns the rectangle bounds of the element and its position relative to the top-left of the viewport of the current document.

      This method can return an empty Rect in the following cases:

      • the element is not attached to the DOM tree;
      • the element is not visible and has the hidden attribute;
      • the CSS style of the element contains display: none; statement.

      If the element is attached to the DOM tree and is visible, but it is out of the viewport, this method still returns its bounds.

      The amount of scrolling that has been done of the viewport area (or any other scrollable element) is taken into account when computing the bounding rectangle. This means that the rectangle's boundary edges (top, left, bottom, and right) change their values every time the scrolling position changes (because their values are relative to the viewport and not absolute). If you need the bounding rectangle relative to the top-left corner of the document, just add the current scrolling position to the top and left properties (these can be obtained using window.scrollX and window.scrollY) to get a bounding rectangle which is independent from the current scrolling position.

      The origin and size of the returned rectangle are in the device-independent pixels.

      Throws:
      ObjectClosedException - when this instance is closed
    • boundingClientRectInViewport

      Rect boundingClientRectInViewport()
      Returns the rectangle bounds of the element and its position relative to the top-left of the viewport of the main document.

      This method can return an empty Rect in the following cases:

      • the element is not attached to the DOM tree;
      • the element is not visible and has the hidden attribute;
      • the CSS style of the element contains display: none; statement.

      If the element is attached to the DOM tree and is visible, but it is out of the viewport, this method still returns its bounds.

      To get the bounding rectangle of the element relative to the viewport of the current document, use the boundingClientRect() method.

      The origin and size of the returned rectangle are in the device-independent pixels.

      Throws:
      ObjectClosedException - when this instance is closed
      Since:
      8.8.0
    • focus

      void focus()
      Sets focus on this element, if it can be focused. The focused element is the element which will receive keyboard and similar events by default.

      This method does nothing if the browser instance where the web page with this element is loaded is not focused. To programmatically focus the browser instance use the Browser.focus() method.

      Throws:
      ObjectClosedException - when this instance is closed
      Since:
      7.1
    • blur

      void blur()
      Removes keyboard focus from the current element.

      This method does nothing if the browser instance where the web page with this element is loaded is not focused. To programmatically focus the browser instance use the Browser.focus() method.

      Throws:
      ObjectClosedException - when this instance is closed
      Since:
      7.1
    • scrollIntoView

      void scrollIntoView(Element.AlignTo alignTo)
      Scrolls the element's parent container such that the element on which this method is called is visible to the user.

      Note: that the element may not be scrolled completely to the top or bottom depending on the layout of other elements.

      Parameters:
      alignTo - describes how the element will be aligned to the visible area of the scrollable ancestor
      Throws:
      ObjectClosedException - when the document of this element is closed
      Since:
      7.5