com.gargoylesoftware.htmlunit.html
Class HtmlForm

java.lang.Object
  extended by com.gargoylesoftware.htmlunit.html.DomNode
      extended by com.gargoylesoftware.htmlunit.html.DomNamespaceNode
          extended by com.gargoylesoftware.htmlunit.html.DomElement
              extended by com.gargoylesoftware.htmlunit.html.HtmlElement
                  extended by com.gargoylesoftware.htmlunit.html.StyledElement
                      extended by com.gargoylesoftware.htmlunit.html.ClickableElement
                          extended by com.gargoylesoftware.htmlunit.html.HtmlForm
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, org.w3c.dom.Element, org.w3c.dom.Node

public class HtmlForm
extends ClickableElement

Wrapper for the HTML element "form".

Version:
$Revision: 4638 $
Author:
Mike Bowler, David K. Taylor, Brad Clarke, Christian Sell, Marc Guillemot, George Murnock, Kent Tong, Ahmed Ashour, Philip Graf
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.gargoylesoftware.htmlunit.html.HtmlElement
HtmlElement.ChildElementsIterator
 
Nested classes/interfaces inherited from class com.gargoylesoftware.htmlunit.html.DomNode
DomNode.ChildIterator, DomNode.DescendantElementsIterator
 
Field Summary
static java.lang.String TAG_NAME
          The HTML tag represented by this element.
 
Fields inherited from class com.gargoylesoftware.htmlunit.html.HtmlElement
TAB_INDEX_OUT_OF_BOUNDS
 
Fields inherited from class com.gargoylesoftware.htmlunit.html.DomElement
ATTRIBUTE_NOT_DEFINED, ATTRIBUTE_VALUE_EMPTY
 
Fields inherited from class com.gargoylesoftware.htmlunit.html.DomNode
AS_TEXT_BLANK, AS_TEXT_BLOCK_SEPARATOR, AS_TEXT_NEW_LINE, AS_TEXT_TAB, PROPERTY_ELEMENT, READY_STATE_COMPLETE, READY_STATE_INTERACTIVE, READY_STATE_LOADED, READY_STATE_LOADING, READY_STATE_UNINITIALIZED
 
Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
 
Method Summary
 java.lang.String getAcceptAttribute()
          Returns the value of the attribute "accept".
 java.lang.String getAcceptCharsetAttribute()
          Returns the value of the attribute "accept-charset".
 java.lang.String getActionAttribute()
          Returns the value of the attribute "action".
 HtmlButton getButtonByCaption(java.lang.String caption)
           
 HtmlButton getButtonByName(java.lang.String name)
          Returns the first HtmlButton element in this form that has the specified name.
 java.util.List<HtmlButton> getButtonsByName(java.lang.String name)
          Returns all the HtmlButton elements in this form that have the specified name.
 HtmlRadioButtonInput getCheckedRadioButton(java.lang.String name)
          Returns the first checked radio button with the specified name.
 java.lang.String getEnctypeAttribute()
          Returns the value of the attribute "enctype".
<I extends HtmlInput>
I
getInputByName(java.lang.String name)
          Returns the first input element which is a member of this form and has the specified name.
<I extends HtmlInput>
I
getInputByValue(java.lang.String value)
          Returns the first input in this form with the specified value.
 java.util.List<HtmlInput> getInputsByName(java.lang.String name)
          Returns all input elements which are members of this form and have the specified name.
 java.util.List<HtmlInput> getInputsByValue(java.lang.String value)
          Returns all the inputs in this form with the specified value.
 java.util.List<HtmlElement> getLostChildren()
          Gets the form elements that may be submitted but that don't belong to the form's children in the DOM due to incorrect HTML code.
 java.lang.String getMethodAttribute()
          Returns the value of the attribute "method".
 java.lang.String getNameAttribute()
          Returns the value of the attribute "name".
 java.lang.String getOnResetAttribute()
          Returns the value of the attribute "onreset".
 java.lang.String getOnSubmitAttribute()
          Returns the value of the attribute "onsubmit".
 java.util.List<HtmlRadioButtonInput> getRadioButtonsByName(java.lang.String name)
          Returns all the HtmlRadioButtonInput elements in this form that have the specified name.
 HtmlSelect getSelectByName(java.lang.String name)
          Returns the first HtmlSelect element in this form that has the specified name.
 java.util.List<HtmlSelect> getSelectsByName(java.lang.String name)
          Returns all the HtmlSelect elements in this form that have the specified name.
 HtmlSubmitInput getSubmitButton()
          Gets the first <input type="submit"> element in this form.
 java.util.List<HtmlSubmitInput> getSubmitButtons()
          Returns all the <input type="submit"> elements in this form.
 java.lang.String getTargetAttribute()
          Returns the value of the attribute "target".
 HtmlTextArea getTextAreaByName(java.lang.String name)
          Returns the first HtmlTextArea element in this form that has the specified name.
 java.util.List<HtmlTextArea> getTextAreasByName(java.lang.String name)
          Returns all the HtmlTextArea elements in this form that have the specified name.
protected  void preventDefault()
          This method is called if the current fired event is canceled by preventDefault() in FireFox, or by returning false in Internet Explorer.
 Page reset()
          Resets this form to its initial values, returning the page contained by this form's window after the reset.
 void setActionAttribute(java.lang.String action)
          Sets the value of the attribute "action".
 void setEnctypeAttribute(java.lang.String encoding)
          Sets the value of the attribute "enctype".
 void setMethodAttribute(java.lang.String method)
          Sets the value of the attribute "method".
 void setNameAttribute(java.lang.String name)
          Sets the value of the attribute "name".
 void setTargetAttribute(java.lang.String target)
          Sets the value of the attribute "target".
 Page submit()
          Submit this form as if the first <input type="submit" button in the form was clicked.
 Page submit(SubmittableElement submitElement)
          INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
 
Methods inherited from class com.gargoylesoftware.htmlunit.html.StyledElement
getClassAttribute, getIdAttribute, getStyleAttribute, getTitleAttribute
 
Methods inherited from class com.gargoylesoftware.htmlunit.html.HtmlElement
addHtmlAttributeChangeListener, appendChildIfNoneExists, blur, checkChildHierarchy, click, click, click, dblClick, dblClick, doClickAction, doType, fireEvent, fireEvent, fireHtmlAttributeAdded, fireHtmlAttributeRemoved, fireHtmlAttributeReplaced, focus, getChildElements, getElementById, getElementsByAttribute, getEnclosingElement, getEnclosingForm, getEnclosingFormOrDie, getEventHandler, getHtmlElementsByTagName, getHtmlElementsByTagNames, getId, getLangAttribute, getNodeName, getOnClickAttribute, getOnDblClickAttribute, getOneHtmlElementByAttribute, getOnKeyDownAttribute, getOnKeyPressAttribute, getOnKeyUpAttribute, getOnMouseDownAttribute, getOnMouseMoveAttribute, getOnMouseOutAttribute, getOnMouseOverAttribute, getOnMouseUpAttribute, getTabIndex, getTextDirectionAttribute, getXmlLangAttribute, hasHtmlElementWithId, isAttributeCaseSensitive, isStateUpdateFirst, isSubmittableByEnter, mouseDown, mouseDown, mouseMove, mouseMove, mouseOut, mouseOut, mouseOver, mouseOver, mouseUp, mouseUp, removeAttribute, removeChild, removeEventHandler, removeHtmlAttributeChangeListener, rightClick, rightClick, setAttributeNS, setEventHandler, setEventHandler, setId, toString, type, type, type, type
 
Methods inherited from class com.gargoylesoftware.htmlunit.html.DomElement
cloneNode, getAttribute, getAttributeNode, getAttributeNodeNS, getAttributeNS, getAttributes, getAttributesMap, getElementsByTagName, getElementsByTagNameNS, getNodeType, getSchemaTypeInfo, getTagName, hasAttribute, hasAttributeNS, hasAttributes, isEmptyXmlTagExpanded, namespaces, printOpeningTagContentAsXml, printXml, removeAttributeNode, removeAttributeNS, setAttribute, setAttributeNode, setAttributeNodeNS, setIdAttribute, setIdAttributeNode, setIdAttributeNS
 
Methods inherited from class com.gargoylesoftware.htmlunit.html.DomNamespaceNode
getLocalName, getNamespaceURI, getPrefix, getQualifiedName, setPrefix
 
Methods inherited from class com.gargoylesoftware.htmlunit.html.DomNode
addDomChangeListener, appendChild, asText, asXml, compareDocumentPosition, fireNodeAdded, fireNodeDeleted, getAllHtmlChildElements, getAncestors, getBaseURI, getByXPath, getCanonicalXPath, getChildNodes, getChildren, getEndColumnNumber, getEndLineNumber, getFeature, getFirstByXPath, getFirstChild, getLastChild, getNextSibling, getNodeValue, getOwnerDocument, getPage, getParentNode, getPreviousSibling, getReadyState, getScriptObject, getStartColumnNumber, getStartLineNumber, getTextContent, getUserData, hasChildNodes, insertBefore, insertBefore, isAncestorOf, isBlock, isDefaultNamespace, isDisplayed, isEqualNode, isSameNode, isSupported, isTrimmedText, lookupNamespaceURI, lookupPrefix, normalize, notifyIncorrectness, onAddedToPage, onAllChildrenAddedToPage, printChildrenAsXml, remove, removeAllChildren, removeChild, removeDomChangeListener, replace, replaceChild, selectNodes, selectSingleNode, setNextSibling, setNodeValue, setParentNode, setPreviousSibling, setReadyState, setScriptObject, setTextContent, setUserData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.w3c.dom.Node
appendChild, compareDocumentPosition, getBaseURI, getChildNodes, getFeature, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getTextContent, getUserData, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeChild, replaceChild, setNodeValue, setPrefix, setTextContent, setUserData
 

Field Detail

TAG_NAME

public static final java.lang.String TAG_NAME
The HTML tag represented by this element.

See Also:
Constant Field Values
Method Detail

submit

public Page submit()
            throws java.io.IOException
Submit this form as if the first <input type="submit" button in the form was clicked.

Throws:
java.io.IOException
See Also:
submit(SubmittableElement)

submit

public Page submit(SubmittableElement submitElement)
            throws java.io.IOException
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.

Submits this form to the server. If submitElement is null, then the submission is treated as if it was triggered by JavaScript, and the onsubmit handler will not be executed.

IMPORTANT: Using this method directly is not the preferred way of submitting forms. Most consumers should emulate the user's actions instead, probably by using something like HtmlElement.click() or HtmlElement.dblClick().

Parameters:
submitElement - the element that caused the submit to occur
Returns:
a new page that reflects the results of this submission
Throws:
java.io.IOException - if an IO error occurs

reset

public Page reset()
Resets this form to its initial values, returning the page contained by this form's window after the reset. Note that the returned page may or may not be the same as the original page, based on JavaScript event handlers, etc.

Returns:
the page contained by this form's window after the reset

getSubmitButtons

public java.util.List<HtmlSubmitInput> getSubmitButtons()
                                                 throws ElementNotFoundException
Returns all the <input type="submit"> elements in this form.

Throws:
ElementNotFoundException

getSubmitButton

public HtmlSubmitInput getSubmitButton()
                                throws ElementNotFoundException
Gets the first <input type="submit"> element in this form.

Throws:
ElementNotFoundException

getInputsByName

public java.util.List<HtmlInput> getInputsByName(java.lang.String name)
Returns all input elements which are members of this form and have the specified name.

Parameters:
name - the input name to search for
Returns:
all input elements which are members of this form and have the specified name

getInputByName

public final <I extends HtmlInput> I getInputByName(java.lang.String name)
                                         throws ElementNotFoundException
Returns the first input element which is a member of this form and has the specified name.

Type Parameters:
I - the input type
Parameters:
name - the input name to search for
Returns:
the first input element which is a member of this form and has the specified name
Throws:
ElementNotFoundException - if there is not input in this form with the specified name

getSelectsByName

public java.util.List<HtmlSelect> getSelectsByName(java.lang.String name)
Returns all the HtmlSelect elements in this form that have the specified name.

Parameters:
name - the name to search for
Returns:
all the HtmlSelect elements in this form that have the specified name

getSelectByName

public HtmlSelect getSelectByName(java.lang.String name)
                           throws ElementNotFoundException
Returns the first HtmlSelect element in this form that has the specified name.

Parameters:
name - the name to search for
Returns:
the first HtmlSelect element in this form that has the specified name
Throws:
ElementNotFoundException - if this form does not contain a HtmlSelect element with the specified name

getButtonsByName

public java.util.List<HtmlButton> getButtonsByName(java.lang.String name)
Returns all the HtmlButton elements in this form that have the specified name.

Parameters:
name - the name to search for
Returns:
all the HtmlButton elements in this form that have the specified name

getButtonByName

public HtmlButton getButtonByName(java.lang.String name)
                           throws ElementNotFoundException
Returns the first HtmlButton element in this form that has the specified name.

Parameters:
name - the name to search for
Returns:
the first HtmlButton element in this form that has the specified name
Throws:
ElementNotFoundException - if this form does not contain a HtmlButton element with the specified name

getButtonByCaption

public HtmlButton getButtonByCaption(java.lang.String caption)
                              throws ElementNotFoundException
Throws:
ElementNotFoundException

getTextAreasByName

public java.util.List<HtmlTextArea> getTextAreasByName(java.lang.String name)
Returns all the HtmlTextArea elements in this form that have the specified name.

Parameters:
name - the name to search for
Returns:
all the HtmlTextArea elements in this form that have the specified name

getTextAreaByName

public HtmlTextArea getTextAreaByName(java.lang.String name)
                               throws ElementNotFoundException
Returns the first HtmlTextArea element in this form that has the specified name.

Parameters:
name - the name to search for
Returns:
the first HtmlTextArea element in this form that has the specified name
Throws:
ElementNotFoundException - if this form does not contain a HtmlTextArea element with the specified name

getRadioButtonsByName

public java.util.List<HtmlRadioButtonInput> getRadioButtonsByName(java.lang.String name)
Returns all the HtmlRadioButtonInput elements in this form that have the specified name.

Parameters:
name - the name to search for
Returns:
all the HtmlRadioButtonInput elements in this form that have the specified name

getCheckedRadioButton

public HtmlRadioButtonInput getCheckedRadioButton(java.lang.String name)
Returns the first checked radio button with the specified name. If none of the radio buttons by that name are checked, this method returns null.

Parameters:
name - the name of the radio button
Returns:
the first checked radio button with the specified name

getActionAttribute

public final java.lang.String getActionAttribute()
Returns the value of the attribute "action". Refer to the HTML 4.01 documentation for details on the use of this attribute.

Returns:
the value of the attribute "action" or an empty string if that attribute isn't defined

setActionAttribute

public final void setActionAttribute(java.lang.String action)
Sets the value of the attribute "action". Refer to the HTML 4.01 documentation for details on the use of this attribute.

Parameters:
action - the value of the attribute "action"

getMethodAttribute

public final java.lang.String getMethodAttribute()
Returns the value of the attribute "method". Refer to the HTML 4.01 documentation for details on the use of this attribute.

Returns:
the value of the attribute "method" or an empty string if that attribute isn't defined

setMethodAttribute

public final void setMethodAttribute(java.lang.String method)
Sets the value of the attribute "method". Refer to the HTML 4.01 documentation for details on the use of this attribute.

Parameters:
method - the value of the attribute "method"

getNameAttribute

public final java.lang.String getNameAttribute()
Returns the value of the attribute "name". Refer to the HTML 4.01 documentation for details on the use of this attribute.

Returns:
the value of the attribute "name" or an empty string if that attribute isn't defined

setNameAttribute

public final void setNameAttribute(java.lang.String name)
Sets the value of the attribute "name". Refer to the HTML 4.01 documentation for details on the use of this attribute.

Parameters:
name - the value of the attribute "name"

getEnctypeAttribute

public final java.lang.String getEnctypeAttribute()
Returns the value of the attribute "enctype". Refer to the HTML 4.01 documentation for details on the use of this attribute. "Enctype" is the encoding type used when submitting a form back to the server.

Returns:
the value of the attribute "enctype" or an empty string if that attribute isn't defined

setEnctypeAttribute

public final void setEnctypeAttribute(java.lang.String encoding)
Sets the value of the attribute "enctype". Refer to the HTML 4.01 documentation for details on the use of this attribute. "Enctype" is the encoding type used when submitting a form back to the server.

Parameters:
encoding - the value of the attribute "enctype"

getOnSubmitAttribute

public final java.lang.String getOnSubmitAttribute()
Returns the value of the attribute "onsubmit". Refer to the HTML 4.01 documentation for details on the use of this attribute.

Returns:
the value of the attribute "onsubmit" or an empty string if that attribute isn't defined

getOnResetAttribute

public final java.lang.String getOnResetAttribute()
Returns the value of the attribute "onreset". Refer to the HTML 4.01 documentation for details on the use of this attribute.

Returns:
the value of the attribute "onreset" or an empty string if that attribute isn't defined

getAcceptAttribute

public final java.lang.String getAcceptAttribute()
Returns the value of the attribute "accept". Refer to the HTML 4.01 documentation for details on the use of this attribute.

Returns:
the value of the attribute "accept" or an empty string if that attribute isn't defined

getAcceptCharsetAttribute

public final java.lang.String getAcceptCharsetAttribute()
Returns the value of the attribute "accept-charset". Refer to the HTML 4.01 documentation for details on the use of this attribute.

Returns:
the value of the attribute "accept-charset" or an empty string if that attribute isn't defined

getTargetAttribute

public final java.lang.String getTargetAttribute()
Returns the value of the attribute "target". Refer to the HTML 4.01 documentation for details on the use of this attribute.

Returns:
the value of the attribute "target" or an empty string if that attribute isn't defined

setTargetAttribute

public final void setTargetAttribute(java.lang.String target)
Sets the value of the attribute "target". Refer to the HTML 4.01 documentation for details on the use of this attribute.

Parameters:
target - the value of the attribute "target"

getInputByValue

public <I extends HtmlInput> I getInputByValue(java.lang.String value)
                                    throws ElementNotFoundException
Returns the first input in this form with the specified value.

Type Parameters:
I - the input type
Parameters:
value - the value to search for
Returns:
the first input in this form with the specified value
Throws:
ElementNotFoundException - if this form does not contain any inputs with the specified value

getInputsByValue

public java.util.List<HtmlInput> getInputsByValue(java.lang.String value)
Returns all the inputs in this form with the specified value.

Parameters:
value - the value to search for
Returns:
all the inputs in this form with the specified value

getLostChildren

public java.util.List<HtmlElement> getLostChildren()
Gets the form elements that may be submitted but that don't belong to the form's children in the DOM due to incorrect HTML code.

Returns:
the elements

preventDefault

protected void preventDefault()
This method is called if the current fired event is canceled by preventDefault() in FireFox, or by returning false in Internet Explorer. The default implementation does nothing.

Overrides:
preventDefault in class HtmlElement


Copyright © 2002-2011 Gargoyle Software Inc.. All Rights Reserved.