Class HtmlForm
java.lang.Object
org.htmlunit.html.DomNode
org.htmlunit.html.DomNamespaceNode
org.htmlunit.html.DomElement
org.htmlunit.html.HtmlElement
org.htmlunit.html.HtmlForm
- All Implemented Interfaces:
Serializable, Cloneable, Element, Node
Wrapper for the HTML element "form".
- Author:
- Mike Bowler, David K. Taylor, Brad Clarke, Christian Sell, Marc Guillemot, George Murnock, Kent Tong, Ahmed Ashour, Philip Graf, Ronald Brill, Frank Danek, Anton Demydenko
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class HtmlElement
HtmlElement.DisplayStyleNested classes/interfaces inherited from class DomElement
DomElement.ChildElementsIteratorNested classes/interfaces inherited from class DomNode
DomNode.ChildIterator, DomNode.DescendantElementsIterator<T> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe "formnovalidate" attribute name.static final StringThe HTML tag represented by this element.Fields inherited from class HtmlElement
ATTRIBUTE_CHECKED, ATTRIBUTE_REQUIRED, TAB_INDEX_OUT_OF_BOUNDSFields inherited from class DomElement
ATTRIBUTE_NOT_DEFINED, ATTRIBUTE_VALUE_EMPTY, ID_ATTRIBUTE, NAME_ATTRIBUTE, SRC_ATTRIBUTE, TYPE_ATTRIBUTE, VALUE_ATTRIBUTEFields inherited from class DomNode
PROPERTY_ELEMENT, READY_STATE_COMPLETE, READY_STATE_INTERACTIVE, READY_STATE_LOADED, READY_STATE_LOADING, READY_STATE_UNINITIALIZEDFields inherited from interface 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
Modifier and TypeMethodDescriptionfinal StringReturns the value of the attributeaccept.final StringReturns the value of the attributeaccept-charset.final StringReturns the value of the attributeaction.getButtonByName(String name) Returns the firstHtmlButtonelement in this form that has the specified name.getButtonsByName(String name) Returns all theHtmlButtonelements in this form that have the specified name.getCheckedRadioButton(String name) Returns the first checked radio button with the specified name.final StringReturns the value of the attributeenctype.final <I extends HtmlInput>
IgetInputByName(String name) Returns the first input element which is a member of this form and has the specified name.<I extends HtmlInput>
IgetInputByValue(String value) Returns the first input in this form with the specified value.getInputsByName(String name) Returns all input elements which are members of this form and have the specified name.getInputsByValue(String value) Returns all the inputs in this form with the specified value.final StringReturns the value of the attributemethod.final StringReturns the value of the attributename.final StringReturns the value of the attributeonreset.final StringReturns the value of the attributeonsubmit.getParameterListForSubmit(SubmittableElement submitElement) INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Returns a list ofNameValuePairs that represent the data that will be sent to the server when this form is submitted.getRadioButtonsByName(String name) Returns all theHtmlRadioButtonInputelements in this form that have the specified name.final StringReturns the value of the attributerel.getSelectByName(String name) Returns the firstHtmlSelectelement in this form that has the specified name.getSelectsByName(String name) Returns all theHtmlSelectelements in this form that have the specified name.final StringReturns the value of the attributetarget.getTextAreaByName(String name) Returns the firstHtmlTextAreaelement in this form that has the specified name.getTextAreasByName(String name) Returns all theHtmlTextAreaelements in this form that have the specified name.getWebRequest(SubmittableElement submitElement) INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Gets the request for a submission of this form with the specified SubmittableElement.protected booleanBrowsers have problems with self closing form tags.final booleanbooleanisValid()Returns whether this element satisfies all form validation constraints set.protected voidThis method is called if the current fired event is canceled bypreventDefault().reset()Resets this form to its initial values, returning the page contained by this form's window after the reset.final voidsetActionAttribute(String action) Sets the value of the attributeaction.final voidsetEnctypeAttribute(String encoding) Sets the value of the attributeenctype.final voidsetMethodAttribute(String method) Sets the value of the attributemethod.final voidsetNameAttribute(String name) Sets the value of the attributename.final voidsetNoValidate(boolean noValidate) Sets the value of the attributenovalidate.final voidsetTargetAttribute(String target) Sets the value of the attributetarget.voidsubmit(SubmittableElement submitElement) INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.Methods inherited from class HtmlElement
acceptChar, addHtmlAttributeChangeListener, appendChildIfNoneExists, checkChildHierarchy, cloneNode, detach, doType, doType, fireHtmlAttributeAdded, fireHtmlAttributeRemoved, fireHtmlAttributeReplaced, getCanonicalXPath, getDefaultStyleDisplay, getElementsByAttribute, getEnclosingElement, getEnclosingForm, getEnclosingFormOrDie, getLangAttribute, getNodeName, getOnClickAttribute, getOnDblClickAttribute, getOneHtmlElementByAttribute, getOnKeyDownAttribute, getOnKeyPressAttribute, getOnKeyUpAttribute, getOnMouseDownAttribute, getOnMouseMoveAttribute, getOnMouseOutAttribute, getOnMouseOverAttribute, getOnMouseUpAttribute, getSrcAttributeNormalized, getTabIndex, getTextDirectionAttribute, getXmlLangAttribute, handles, hasEventHandlers, isAltPressed, isAttributeCaseSensitive, isCtrlPressed, isDisplayed, isHidden, isOptional, isRequired, isRequiredSupported, isShiftPressed, isSubmittableByEnter, notifyAttributeChangeListeners, removeAttribute, removeChild, removeHtmlAttributeChangeListener, setAttributeNode, setAttributeNS, setOwningForm, setRequired, type, type, type, type, typeDoneMethods inherited from class DomElement
blur, click, click, click, click, click, dblClick, dblClick, doClickFireChangeEvent, doClickFireClickEvent, doClickStateUpdate, fireEvent, fireEvent, focus, getAttribute, getAttributeDirect, getAttributeNode, getAttributeNodeNS, getAttributeNS, getAttributes, getAttributesMap, getChildElementCount, getChildElements, getElementsByTagName, getElementsByTagNameNS, getEventTargetElement, getFirstElementChild, getId, getLastElementChild, getNodeType, getSchemaTypeInfo, getStyleElement, getStyleElementCaseInSensitive, getStyleMap, getTagName, hasAttribute, hasAttributeNS, hasAttributes, isDisabledElementAndDisabled, isMouseOver, isStateUpdateFirst, matches, mouseDown, mouseDown, mouseMove, mouseMove, mouseOut, mouseOut, mouseOver, mouseOver, mouseUp, mouseUp, printOpeningTagContentAsXml, printXml, propagateClickStateUpdateToParent, removeAttributeNode, removeAttributeNS, removeFocus, removeStyleAttribute, replaceStyleAttribute, rightClick, rightClick, setAttribute, setAttributeNodeNS, setAttributeNS, setDefaults, setId, setIdAttribute, setIdAttributeNode, setIdAttributeNS, setInnerHtml, setNodeValue, toString, writeStyleToElementMethods inherited from class DomNamespaceNode
getLocalName, getLowercaseName, getNamespaceURI, getPrefix, getQualifiedName, processImportNode, setPrefixMethods inherited from class DomNode
addCharacterDataChangeListener, addDomChangeListener, appendChild, asNormalizedText, asXml, basicRemove, closest, compareDocumentPosition, fireCharacterDataChanged, fireNodeAdded, fireNodeDeleted, getAncestors, getBaseURI, getByXPath, getByXPath, getChildNodes, getChildren, getDescendants, getDomElementDescendants, getEndColumnNumber, getEndLineNumber, getFeature, getFirstByXPath, getFirstByXPath, getFirstChild, getHtmlElementDescendants, getHtmlPageOrNull, getIndex, getLastChild, getNextElementSibling, getNextSibling, getNodeValue, getOwnerDocument, getPage, getParentNode, getPreviousElementSibling, getPreviousSibling, getReadyState, getScriptableObject, getSelectorList, getStartColumnNumber, getStartLineNumber, getTextContent, getUserData, getVisibleText, hasChildNodes, hasFeature, insertBefore, insertBefore, isAncestorOf, isAncestorOfAny, isAttachedToPage, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, mayBeDisplayed, normalize, notifyIncorrectness, onAddedToDocumentFragment, onAddedToPage, onAllChildrenAddedToPage, parseHtmlSnippet, printChildrenAsXml, querySelector, querySelectorAll, quietlyRemoveAndMoveChildrenTo, remove, removeAllChildren, removeCharacterDataChangeListener, removeChild, removeDomChangeListener, replace, replaceChild, setEndLocation, setParentNode, setReadyState, setScriptableObject, setStartLocation, setTextContent, setUserDataMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface 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, setPrefix, setTextContent, setUserData
-
Field Details
-
TAG_NAME
-
ATTRIBUTE_FORMNOVALIDATE
-
-
Method Details
-
submit
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Submits this form to the server. If
submitElementisnull, then the submission is treated as if it was triggered by JavaScript, and theonsubmithandler 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
DomElement.click()orDomElement.dblClick().- Parameters:
submitElement- the element that caused the submit to occur
-
getWebRequest
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Gets the request for a submission of this form with the specified SubmittableElement.- Parameters:
submitElement- the element that caused the submit to occur- Returns:
- the request
-
getParameterListForSubmit
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Returns a list ofNameValuePairs that represent the data that will be sent to the server when this form is submitted. This is primarily intended to aid debugging.- Parameters:
submitElement- the element used to submit the form, ornullif the form was submitted by JavaScript- Returns:
- the list of
NameValuePairs that represent that data that will be sent to the server when this form is submitted
-
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
-
isValid
public boolean isValid()Returns whether this element satisfies all form validation constraints set.- Overrides:
isValidin classHtmlElement- Returns:
- whether this element satisfies all form validation constraints set
-
getInputsByName
-
getElements
- Returns:
- returns a list of all form controls contained in the <form> element or referenced by formId but ignoring elements that are contained in a nested form
-
getInputByName
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
Returns all theHtmlSelectelements in this form that have the specified name.- Parameters:
name- the name to search for- Returns:
- all the
HtmlSelectelements in this form that have the specified name
-
getSelectByName
Returns the firstHtmlSelectelement in this form that has the specified name.- Parameters:
name- the name to search for- Returns:
- the first
HtmlSelectelement in this form that has the specified name - Throws:
ElementNotFoundException- if this form does not contain aHtmlSelectelement with the specified name
-
getButtonsByName
Returns all theHtmlButtonelements in this form that have the specified name.- Parameters:
name- the name to search for- Returns:
- all the
HtmlButtonelements in this form that have the specified name
-
getButtonByName
Returns the firstHtmlButtonelement in this form that has the specified name.- Parameters:
name- the name to search for- Returns:
- the first
HtmlButtonelement in this form that has the specified name - Throws:
ElementNotFoundException- if this form does not contain aHtmlButtonelement with the specified name
-
getTextAreasByName
Returns all theHtmlTextAreaelements in this form that have the specified name.- Parameters:
name- the name to search for- Returns:
- all the
HtmlTextAreaelements in this form that have the specified name
-
getTextAreaByName
Returns the firstHtmlTextAreaelement in this form that has the specified name.- Parameters:
name- the name to search for- Returns:
- the first
HtmlTextAreaelement in this form that has the specified name - Throws:
ElementNotFoundException- if this form does not contain aHtmlTextAreaelement with the specified name
-
getRadioButtonsByName
Returns all theHtmlRadioButtonInputelements in this form that have the specified name.- Parameters:
name- the name to search for- Returns:
- all the
HtmlRadioButtonInputelements in this form that have the specified name
-
getCheckedRadioButton
Returns the first checked radio button with the specified name. If none of the radio buttons by that name are checked, this method returnsnull.- Parameters:
name- the name of the radio button- Returns:
- the first checked radio button with the specified name
-
getActionAttribute
-
setActionAttribute
-
getMethodAttribute
-
setMethodAttribute
-
getNameAttribute
-
setNameAttribute
-
getEnctypeAttribute
Returns the value of the attributeenctype. 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
enctypeor an empty string if that attribute isn't defined
-
setEnctypeAttribute
Sets the value of the attributeenctype. 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 attributeenctype
-
getOnSubmitAttribute
-
getOnResetAttribute
-
getAcceptAttribute
-
getAcceptCharsetAttribute
-
getTargetAttribute
-
setTargetAttribute
-
getRelAttribute
-
getInputByValue
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
-
preventDefault
protected void preventDefault()This method is called if the current fired event is canceled bypreventDefault().The default implementation does nothing.
- Overrides:
preventDefaultin classDomElement
-
isEmptyXmlTagExpanded
protected boolean isEmptyXmlTagExpanded()Browsers have problems with self closing form tags.- Overrides:
isEmptyXmlTagExpandedin classDomElement- Returns:
falseby default
-
isNoValidate
public final boolean isNoValidate()- Returns:
- the value of the attribute
novalidateor an empty string if that attribute isn't defined
-
setNoValidate
public final void setNoValidate(boolean noValidate) Sets the value of the attributenovalidate.- Parameters:
noValidate- the value of the attributenovalidate
-