Class HtmlUnitWebElement

java.lang.Object
org.openqa.selenium.htmlunit.HtmlUnitWebElement
All Implemented Interfaces:
org.openqa.selenium.interactions.Coordinates, org.openqa.selenium.interactions.Locatable, org.openqa.selenium.SearchContext, org.openqa.selenium.TakesScreenshot, org.openqa.selenium.WebElement, org.openqa.selenium.WrapsDriver

public class HtmlUnitWebElement extends Object implements org.openqa.selenium.WrapsDriver, org.openqa.selenium.WebElement, org.openqa.selenium.interactions.Coordinates, org.openqa.selenium.interactions.Locatable
Represents an HTML element in the context of HtmlUnitDriver.

Implements WebElement, Coordinates, and Locatable interfaces to provide standard Selenium interactions, including clicking, submitting forms, reading attributes, and determining location and size.

This class wraps a DomElement and delegates operations to HtmlUnitDriver where appropriate.

It also handles submit logic for forms, manages element state checks (like visibility, enabled/disabled, stale elements), and supports reading CSS values and DOM properties.

Author:
Alexei Barantsev, Ahmed Ashour, Javier Neira, Ronald Brill, Andrei Solntsev, Martin Bartoš, Scott Babcock
  • Constructor Details

  • Method Details

    • click

      public void click()
      Specified by:
      click in interface org.openqa.selenium.WebElement
    • submit

      public void submit()
      Specified by:
      submit in interface org.openqa.selenium.WebElement
    • clear

      public void clear()
      Specified by:
      clear in interface org.openqa.selenium.WebElement
    • sendKeys

      public void sendKeys(CharSequence... value)
      Specified by:
      sendKeys in interface org.openqa.selenium.WebElement
    • getTagName

      public String getTagName()
      Specified by:
      getTagName in interface org.openqa.selenium.WebElement
    • getAttribute

      public String getAttribute(String name)
      Specified by:
      getAttribute in interface org.openqa.selenium.WebElement
    • getDomProperty

      public String getDomProperty(String name)
      Specified by:
      getDomProperty in interface org.openqa.selenium.WebElement
    • getDomAttribute

      public String getDomAttribute(String name)
      Specified by:
      getDomAttribute in interface org.openqa.selenium.WebElement
    • isSelected

      public boolean isSelected()
      Specified by:
      isSelected in interface org.openqa.selenium.WebElement
    • isEnabled

      public boolean isEnabled()
      Specified by:
      isEnabled in interface org.openqa.selenium.WebElement
    • isDisplayed

      public boolean isDisplayed()
      Specified by:
      isDisplayed in interface org.openqa.selenium.WebElement
    • getLocation

      public org.openqa.selenium.Point getLocation()
      Specified by:
      getLocation in interface org.openqa.selenium.WebElement
    • getSize

      public org.openqa.selenium.Dimension getSize()
      Specified by:
      getSize in interface org.openqa.selenium.WebElement
    • getRect

      public org.openqa.selenium.Rectangle getRect()
      Specified by:
      getRect in interface org.openqa.selenium.WebElement
    • getText

      public String getText()
      Specified by:
      getText in interface org.openqa.selenium.WebElement
    • getDriver

      protected HtmlUnitDriver getDriver()
      Returns the HtmlUnitDriver associated with this element.
      Returns:
      the driver instance that owns this element
    • getElement

      public DomElement getElement()
      Returns the underlying DomElement wrapped by this WebElement.
      Returns:
      the wrapped DomElement
    • getElementsByTagName

      @Deprecated public List<org.openqa.selenium.WebElement> getElementsByTagName(String tagName)
      Deprecated.
      It's not a part of WebDriver API
      Returns a list of child elements with the specified tag name.

      This method is deprecated because it is not part of the official WebDriver API. Consider using findElements(By) instead.

      Parameters:
      tagName - the tag name to search for among the descendants of this element
      Returns:
      a list of matching WebElement instances
    • findElement

      public org.openqa.selenium.WebElement findElement(org.openqa.selenium.By by)
      Specified by:
      findElement in interface org.openqa.selenium.SearchContext
      Specified by:
      findElement in interface org.openqa.selenium.WebElement
    • findElements

      public List<org.openqa.selenium.WebElement> findElements(org.openqa.selenium.By by)
      Specified by:
      findElements in interface org.openqa.selenium.SearchContext
      Specified by:
      findElements in interface org.openqa.selenium.WebElement
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • assertElementNotStale

      protected void assertElementNotStale()
      Verifies that this element is not stale.

      An element is considered stale if it has been removed from the DOM or if the page it belongs to has been refreshed or navigated away. If the element is stale, the underlying HtmlUnitDriver will throw a StaleElementReferenceException.

    • getCssValue

      public String getCssValue(String propertyName)
      Specified by:
      getCssValue in interface org.openqa.selenium.WebElement
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getWrappedDriver

      public org.openqa.selenium.WebDriver getWrappedDriver()
      Specified by:
      getWrappedDriver in interface org.openqa.selenium.WrapsDriver
    • getCoordinates

      public org.openqa.selenium.interactions.Coordinates getCoordinates()
      Specified by:
      getCoordinates in interface org.openqa.selenium.interactions.Locatable
    • onScreen

      public org.openqa.selenium.Point onScreen()
      Specified by:
      onScreen in interface org.openqa.selenium.interactions.Coordinates
    • inViewPort

      public org.openqa.selenium.Point inViewPort()
      Specified by:
      inViewPort in interface org.openqa.selenium.interactions.Coordinates
    • onPage

      public org.openqa.selenium.Point onPage()
      Specified by:
      onPage in interface org.openqa.selenium.interactions.Coordinates
    • getAuxiliary

      public Object getAuxiliary()
      Specified by:
      getAuxiliary in interface org.openqa.selenium.interactions.Coordinates
    • getScreenshotAs

      public <X> X getScreenshotAs(org.openqa.selenium.OutputType<X> outputType) throws org.openqa.selenium.WebDriverException
      Specified by:
      getScreenshotAs in interface org.openqa.selenium.TakesScreenshot
      Throws:
      org.openqa.selenium.WebDriverException
    • getId

      public int getId()
      Returns the unique identifier assigned to this element within the HtmlUnitDriver.
      Returns:
      the element's unique ID
    • toJson

      public Map<String,Object> toJson()
      Converts this element into a JSON representation suitable for WebDriver communication.

      The resulting map includes the encoded element key as defined by the W3C WebDriver specification, with this element's unique ID as the value.

      Returns:
      a Map representing this element in JSON format