org.openqa.selenium.htmlunit
Class HtmlUnitWebElement

java.lang.Object
  extended by org.openqa.selenium.htmlunit.HtmlUnitWebElement
All Implemented Interfaces:
FindsByCssSelector, FindsById, FindsByLinkText, FindsByTagName, FindsByXPath, Locatable, WrapsDriver, SearchContext, WebElement

public class HtmlUnitWebElement
extends Object
implements WrapsDriver, FindsById, FindsByLinkText, FindsByXPath, FindsByTagName, FindsByCssSelector, Locatable, WebElement


Field Summary
protected  com.gargoylesoftware.htmlunit.html.HtmlElement element
           
protected  HtmlUnitDriver parent
           
 
Constructor Summary
HtmlUnitWebElement(HtmlUnitDriver parent, com.gargoylesoftware.htmlunit.html.HtmlElement element)
           
 
Method Summary
protected  void assertElementNotStale()
           
 void clear()
          If this element is a text entry element, this will clear the value.
 void click()
          Click this element.
 boolean equals(Object obj)
           
 WebElement findElement(By by)
          Find the first WebElement using the given method.
 WebElement findElementByCssSelector(String using)
           
 WebElement findElementById(String id)
           
 WebElement findElementByLinkText(String linkText)
           
 WebElement findElementByPartialLinkText(String linkText)
           
 WebElement findElementByTagName(String name)
           
 WebElement findElementByXPath(String xpathExpr)
           
 List<WebElement> findElements(By by)
          Find all elements within the current context using the given mechanism.
 List<WebElement> findElementsByCssSelector(String using)
           
 List<WebElement> findElementsById(String id)
           
 List<WebElement> findElementsByLinkText(String linkText)
           
 List<WebElement> findElementsByPartialLinkText(String linkText)
           
 List<WebElement> findElementsByTagName(String name)
           
 List<WebElement> findElementsByXPath(String xpathExpr)
           
 String getAttribute(String name)
          Get the value of a the given attribute of the element.
 Coordinates getCoordinates()
           
 String getCssValue(String propertyName)
          Get the value of a given CSS property.
protected  com.gargoylesoftware.htmlunit.html.HtmlElement getElement()
           
 List<WebElement> getElementsByTagName(String tagName)
           
 Point getLocation()
          Where on the page is the top left-hand corner of the rendered element?
 Point getLocationOnScreenOnceScrolledIntoView()
          Use this to discover where on the screen an element is so that we can click it.
protected  HtmlUnitDriver getParent()
           
 Dimension getSize()
          What is the width and height of the rendered element?
 String getTagName()
          Get the tag name of this element.
 String getText()
          Get the visible (i.e.
 WebDriver getWrappedDriver()
           
 int hashCode()
           
 boolean isDisplayed()
          Is this element displayed or not? This method avoids the problem of having to parse an element's "style" attribute.
 boolean isEnabled()
          Is the element currently enabled or not? This will generally return true for everything but disabled input elements.
 boolean isSelected()
          Determine whether or not this element is selected or not.
 void sendKeyDownEvent(Keys modifierKey)
           
 void sendKeys(CharSequence... value)
          Use this method to simulate typing into an element, which may set its value.
 void sendKeyUpEvent(Keys modifierKey)
           
 void setSelected()
           
 void submit()
          If this current element is a form, or an element within a form, then this will be submitted to the remote server.
 boolean toggle()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

parent

protected final HtmlUnitDriver parent

element

protected final com.gargoylesoftware.htmlunit.html.HtmlElement element
Constructor Detail

HtmlUnitWebElement

public HtmlUnitWebElement(HtmlUnitDriver parent,
                          com.gargoylesoftware.htmlunit.html.HtmlElement element)
Method Detail

click

public void click()
Description copied from interface: WebElement
Click this element. If this causes a new page to load, this method will block until the page has loaded. At this point, you should discard all references to this element and any further operations performed on this element will have undefined behaviour unless you know that the element and the page will still be present. If click() causes a new page to be loaded via an event or is done by sending a native event (which is a common case on Firefox, IE on Windows) then the method will *not* wait for it to be loaded and the caller should verify that a new page has been loaded.

If this element is not clickable, then this operation is a no-op since it's pretty common for someone to accidentally miss the target when clicking in Real Life

Specified by:
click in interface WebElement

submit

public void submit()
Description copied from interface: WebElement
If this current element is a form, or an element within a form, then this will be submitted to the remote server. If this causes the current page to change, then this method will block until the new page is loaded.

Specified by:
submit in interface WebElement

clear

public void clear()
Description copied from interface: WebElement
If this element is a text entry element, this will clear the value. Has no effect on other elements. Text entry elements are INPUT and TEXTAREA elements.

Specified by:
clear in interface WebElement

sendKeyDownEvent

public void sendKeyDownEvent(Keys modifierKey)

sendKeyUpEvent

public void sendKeyUpEvent(Keys modifierKey)

sendKeys

public void sendKeys(CharSequence... value)
Description copied from interface: WebElement
Use this method to simulate typing into an element, which may set its value.

Specified by:
sendKeys in interface WebElement

getTagName

public String getTagName()
Description copied from interface: WebElement
Get the tag name of this element. Not the value of the name attribute: will return "input" for the element <input name="foo" />.

Specified by:
getTagName in interface WebElement
Returns:
The tag name of this element.

getAttribute

public String getAttribute(String name)
Description copied from interface: WebElement
Get the value of a the given attribute of the element. Will return the current value, even if this has been modified after the page has been loaded. More exactly, this method will return the value of the given attribute, unless that attribute is not present, in which case the value of the property with the same name is returned. If neither value is set, null is returned. The "style" attribute is converted as best can be to a text representation with a trailing semi-colon. The following are deemed to be "boolean" attributes, and will return either "true" or "false": async, autofocus, autoplay, checked, compact, complete, controls, declare, defaultchecked, defaultselected, defer, disabled, draggable, ended, formnovalidate, hidden, indeterminate, iscontenteditable, ismap, itemscope, loop, multiple, muted, nohref, noresize, noshade, novalidate, nowrap, open, paused, pubdate, readonly, required, reversed, scoped, seamless, seeking, selected, spellcheck, truespeed, willvalidate Finally, the following commonly mis-capitalized attribute/property names are evaluated as expected:

Specified by:
getAttribute in interface WebElement
Parameters:
name - The name of the attribute.
Returns:
The attribute's current value or null if the value is not set.

toggle

public boolean toggle()

isSelected

public boolean isSelected()
Description copied from interface: WebElement
Determine whether or not this element is selected or not. This operation only applies to input elements such as checkboxes, options in a select and radio buttons.

Specified by:
isSelected in interface WebElement
Returns:
True if the element is currently selected or checked, false otherwise.

setSelected

public void setSelected()

isEnabled

public boolean isEnabled()
Description copied from interface: WebElement
Is the element currently enabled or not? This will generally return true for everything but disabled input elements.

Specified by:
isEnabled in interface WebElement
Returns:
True if the element is enabled, false otherwise.

isDisplayed

public boolean isDisplayed()
Description copied from interface: WebElement
Is this element displayed or not? This method avoids the problem of having to parse an element's "style" attribute.

Specified by:
isDisplayed in interface WebElement
Returns:
Whether or not the element is displayed

getLocation

public Point getLocation()
Description copied from interface: WebElement
Where on the page is the top left-hand corner of the rendered element?

Specified by:
getLocation in interface WebElement
Returns:
A point, containing the location of the top left-hand corner of the element

getSize

public Dimension getSize()
Description copied from interface: WebElement
What is the width and height of the rendered element?

Specified by:
getSize in interface WebElement
Returns:
The size of the element on the page.

getText

public String getText()
Description copied from interface: WebElement
Get the visible (i.e. not hidden by CSS) innerText of this element, including sub-elements, without any leading or trailing whitespace.

Specified by:
getText in interface WebElement
Returns:
The innerText of this element.

getParent

protected HtmlUnitDriver getParent()

getElement

protected com.gargoylesoftware.htmlunit.html.HtmlElement getElement()

getElementsByTagName

public List<WebElement> getElementsByTagName(String tagName)

findElement

public WebElement findElement(By by)
Description copied from interface: WebElement
Find the first WebElement using the given method. See the note in WebElement.findElement(By) about finding via XPath.

Specified by:
findElement in interface SearchContext
Specified by:
findElement in interface WebElement
Parameters:
by - The locating mechanism
Returns:
The first matching element on the current context.

findElements

public List<WebElement> findElements(By by)
Description copied from interface: WebElement
Find all elements within the current context using the given mechanism. When using xpath be aware that webdriver follows standard conventions: a search prefixed with "//" will search the entire document, not just the children of this current node. Use ".//" to limit your search to the children of this WebElement.

Specified by:
findElements in interface SearchContext
Specified by:
findElements in interface WebElement
Parameters:
by - The locating mechanism to use
Returns:
A list of all WebElements, or an empty list if nothing matches.
See Also:
By

findElementById

public WebElement findElementById(String id)
Specified by:
findElementById in interface FindsById

findElementsById

public List<WebElement> findElementsById(String id)
Specified by:
findElementsById in interface FindsById

findElementsByCssSelector

public List<WebElement> findElementsByCssSelector(String using)
Specified by:
findElementsByCssSelector in interface FindsByCssSelector

findElementByCssSelector

public WebElement findElementByCssSelector(String using)
Specified by:
findElementByCssSelector in interface FindsByCssSelector

findElementByXPath

public WebElement findElementByXPath(String xpathExpr)
Specified by:
findElementByXPath in interface FindsByXPath

findElementsByXPath

public List<WebElement> findElementsByXPath(String xpathExpr)
Specified by:
findElementsByXPath in interface FindsByXPath

findElementByLinkText

public WebElement findElementByLinkText(String linkText)
Specified by:
findElementByLinkText in interface FindsByLinkText

findElementsByLinkText

public List<WebElement> findElementsByLinkText(String linkText)
Specified by:
findElementsByLinkText in interface FindsByLinkText

findElementByPartialLinkText

public WebElement findElementByPartialLinkText(String linkText)
Specified by:
findElementByPartialLinkText in interface FindsByLinkText

findElementsByPartialLinkText

public List<WebElement> findElementsByPartialLinkText(String linkText)
Specified by:
findElementsByPartialLinkText in interface FindsByLinkText

findElementByTagName

public WebElement findElementByTagName(String name)
Specified by:
findElementByTagName in interface FindsByTagName

findElementsByTagName

public List<WebElement> findElementsByTagName(String name)
Specified by:
findElementsByTagName in interface FindsByTagName

toString

public String toString()
Overrides:
toString in class Object

assertElementNotStale

protected void assertElementNotStale()

getCssValue

public String getCssValue(String propertyName)
Description copied from interface: WebElement
Get the value of a given CSS property. This is probably not going to return what you expect it to unless you've already had a look at the element using something like firebug. Seriously, even then you'll be lucky for this to work cross-browser. Colour values should be returned as hex strings, so, for example if the "background-color" property is set as "green" in the HTML source, the returned value will be "#008000"

Specified by:
getCssValue in interface WebElement
Returns:
The current, computed value of the property.

equals

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

hashCode

public int hashCode()
Overrides:
hashCode in class Object

getWrappedDriver

public WebDriver getWrappedDriver()
Specified by:
getWrappedDriver in interface WrapsDriver
Returns:
The driver that contains this element.

getLocationOnScreenOnceScrolledIntoView

public Point getLocationOnScreenOnceScrolledIntoView()
Description copied from interface: Locatable
Use this to discover where on the screen an element is so that we can click it. This method should cause the element to be scrolled into view.

Specified by:
getLocationOnScreenOnceScrolledIntoView in interface Locatable
Returns:
The top lefthand corner location on the screen, or null if the element is not visible

getCoordinates

public Coordinates getCoordinates()
Specified by:
getCoordinates in interface Locatable


Copyright © 2011. All Rights Reserved.