Class 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
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 Summary
ConstructorsConstructorDescriptionHtmlUnitWebElement(HtmlUnitDriver driver, int id, DomElement element) Constructs a newHtmlUnitWebElementthat wraps the givenDomElement. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidVerifies that this element is not stale.voidclear()voidclick()booleanorg.openqa.selenium.WebElementfindElement(org.openqa.selenium.By by) List<org.openqa.selenium.WebElement>findElements(org.openqa.selenium.By by) getAttribute(String name) org.openqa.selenium.interactions.CoordinatesgetCssValue(String propertyName) getDomAttribute(String name) getDomProperty(String name) protected HtmlUnitDriverReturns theHtmlUnitDriverassociated with this element.Returns the underlyingDomElementwrapped by thisWebElement.List<org.openqa.selenium.WebElement>getElementsByTagName(String tagName) Deprecated.It's not a part of WebDriver APIintgetId()Returns the unique identifier assigned to this element within theHtmlUnitDriver.org.openqa.selenium.Pointorg.openqa.selenium.RectanglegetRect()<X> XgetScreenshotAs(org.openqa.selenium.OutputType<X> outputType) org.openqa.selenium.DimensiongetSize()getText()org.openqa.selenium.WebDriverinthashCode()org.openqa.selenium.Pointbooleanbooleanbooleanorg.openqa.selenium.PointonPage()org.openqa.selenium.PointonScreen()voidsendKeys(CharSequence... value) voidsubmit()toJson()Converts this element into a JSON representation suitable for WebDriver communication.toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.openqa.selenium.WebElement
getAccessibleName, getAriaRole, getShadowRoot
-
Constructor Details
-
HtmlUnitWebElement
Constructs a newHtmlUnitWebElementthat wraps the givenDomElement.- Parameters:
driver- theHtmlUnitDriverinstance this element belongs toid- a unique identifier for this element within the driverelement- the underlyingDomElementto wrap
-
-
Method Details
-
click
public void click()- Specified by:
clickin interfaceorg.openqa.selenium.WebElement
-
submit
public void submit()- Specified by:
submitin interfaceorg.openqa.selenium.WebElement
-
clear
public void clear()- Specified by:
clearin interfaceorg.openqa.selenium.WebElement
-
sendKeys
- Specified by:
sendKeysin interfaceorg.openqa.selenium.WebElement
-
getTagName
- Specified by:
getTagNamein interfaceorg.openqa.selenium.WebElement
-
getAttribute
- Specified by:
getAttributein interfaceorg.openqa.selenium.WebElement
-
getDomProperty
- Specified by:
getDomPropertyin interfaceorg.openqa.selenium.WebElement
-
getDomAttribute
- Specified by:
getDomAttributein interfaceorg.openqa.selenium.WebElement
-
isSelected
public boolean isSelected()- Specified by:
isSelectedin interfaceorg.openqa.selenium.WebElement
-
isEnabled
public boolean isEnabled()- Specified by:
isEnabledin interfaceorg.openqa.selenium.WebElement
-
isDisplayed
public boolean isDisplayed()- Specified by:
isDisplayedin interfaceorg.openqa.selenium.WebElement
-
getLocation
public org.openqa.selenium.Point getLocation()- Specified by:
getLocationin interfaceorg.openqa.selenium.WebElement
-
getSize
public org.openqa.selenium.Dimension getSize()- Specified by:
getSizein interfaceorg.openqa.selenium.WebElement
-
getRect
public org.openqa.selenium.Rectangle getRect()- Specified by:
getRectin interfaceorg.openqa.selenium.WebElement
-
getText
- Specified by:
getTextin interfaceorg.openqa.selenium.WebElement
-
getDriver
Returns theHtmlUnitDriverassociated with this element.- Returns:
- the driver instance that owns this element
-
getElement
Returns the underlyingDomElementwrapped by thisWebElement.- Returns:
- the wrapped
DomElement
-
getElementsByTagName
Deprecated.It's not a part of WebDriver APIReturns 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
WebElementinstances
-
findElement
public org.openqa.selenium.WebElement findElement(org.openqa.selenium.By by) - Specified by:
findElementin interfaceorg.openqa.selenium.SearchContext- Specified by:
findElementin interfaceorg.openqa.selenium.WebElement
-
findElements
- Specified by:
findElementsin interfaceorg.openqa.selenium.SearchContext- Specified by:
findElementsin interfaceorg.openqa.selenium.WebElement
-
toString
-
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
HtmlUnitDriverwill throw aStaleElementReferenceException. -
getCssValue
- Specified by:
getCssValuein interfaceorg.openqa.selenium.WebElement
-
equals
-
hashCode
public int hashCode() -
getWrappedDriver
public org.openqa.selenium.WebDriver getWrappedDriver()- Specified by:
getWrappedDriverin interfaceorg.openqa.selenium.WrapsDriver
-
getCoordinates
public org.openqa.selenium.interactions.Coordinates getCoordinates()- Specified by:
getCoordinatesin interfaceorg.openqa.selenium.interactions.Locatable
-
onScreen
public org.openqa.selenium.Point onScreen()- Specified by:
onScreenin interfaceorg.openqa.selenium.interactions.Coordinates
-
inViewPort
public org.openqa.selenium.Point inViewPort()- Specified by:
inViewPortin interfaceorg.openqa.selenium.interactions.Coordinates
-
onPage
public org.openqa.selenium.Point onPage()- Specified by:
onPagein interfaceorg.openqa.selenium.interactions.Coordinates
-
getAuxiliary
- Specified by:
getAuxiliaryin interfaceorg.openqa.selenium.interactions.Coordinates
-
getScreenshotAs
public <X> X getScreenshotAs(org.openqa.selenium.OutputType<X> outputType) throws org.openqa.selenium.WebDriverException - Specified by:
getScreenshotAsin interfaceorg.openqa.selenium.TakesScreenshot- Throws:
org.openqa.selenium.WebDriverException
-
getId
public int getId()Returns the unique identifier assigned to this element within theHtmlUnitDriver.- Returns:
- the element's unique ID
-
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
Maprepresenting this element in JSON format
-