Package com.meterware.httpunit
Class WebForm
java.lang.Object
com.meterware.httpunit.WebRequestSource
com.meterware.httpunit.WebForm
- All Implemented Interfaces:
HTMLElement
,com.meterware.httpunit.protocol.ParameterCollection
,ScriptingEventHandler
This class represents a form in an HTML page. Users of this class may examine the parameters
defined for the form, the structure of the form (as a DOM), or the text of the form. They
may also create a
WebRequest
to simulate the submission of the form.- Author:
- Russell Gold
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final HTMLElementPredicate
Predicate to match a link's name. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addPresetParameter
(String name, String value) Records a parameter defined by including it in the destination URL.Returns the action defined for this form.getButton
(HTMLElementPredicate predicate, Object criteria) Button[]
Returns an array containing all of the buttons defined for this form.getButtonWithID
(String buttonID) Convenience method which returns the button with the specified ID.Returns the character set encoding for this form.Returns the form control which is part of this form with the specified ID.protected String
Returns the method defined for this form.int
getNumTextParameters
(String name) Returns the number of text parameters in this form with the specified name.String[]
getOptions
(String name) Returns the displayed options defined for the specified parameter name.String[]
getOptionValues
(String name) Returns the option values defined for the specified parameter name.getParameter
(String name) get the form parameter with the given nameString[]
Returns an array containing the names of the parameters defined for this form.getParameterValue
(String name) Returns the default value of the named parameter.String[]
getParameterValues
(String name) Returns the multiple default values of the named parameter.Creates and returns a web request which will simulate the submission of this form with an unnamed submit button.getRequest
(SubmitButton button) Creates and returns a web request which will simulate the submission of this form by pressing the specified button.getRequest
(SubmitButton button, int x, int y) Creates and returns a web request which will simulate the submission of this form by pressing the specified button.getRequest
(String submitButtonName) Creates and returns a web request which will simulate the submission of this form with a button with the specified name.getRequest
(String submitButtonName, String submitButtonValue) Creates and returns a web request which will simulate the submission of this form with a button with the specified name and value.getSubmitButton
(String name) Returns the submit button defined in this form with the specified name.getSubmitButton
(String name, String value) Returns the submit button defined in this form with the specified name and value.Returns an array containing the submit buttons defined for this form.Returns the submit button defined in this form with the specified ID.boolean
hasParameterNamed
(String soughtName) Returns true if a parameter with given name exists in this form.boolean
hasParameterStartingWithPrefix
(String prefix) Returns true if a parameter starting with a given name exists,boolean
isDisabledParameter
(String name) Returns true if the named parameter is disabled.boolean
isFileParameter
(String name) Returns true if the named parameter accepts files for upload.boolean
isHiddenParameter
(String name) Returns true if the named parameter is hidden.boolean
isMultiValuedParameter
(String name) Returns true if the named parameter accepts multiple values.boolean
isReadOnlyParameter
(String name) Returns true if the named parameter is read-only.boolean
Returns true if this form is to be submitted using mime encoding (the default is URL encoding).boolean
isTextParameter
(String name) Returns true if the named parameter accepts free-form text.Creates and returns a web request based on the current state of this form.newUnvalidatedRequest
(SubmitButton button) Creates and returns a web request which includes the specified button.newUnvalidatedRequest
(SubmitButton button, int x, int y) Creates and returns a web request which includes the specified button and position.void
recordParameters
(com.meterware.httpunit.protocol.ParameterProcessor processor) Iterates through the parameters in this holder, recording them in the supplied parameter processor.void
removeParameter
(String name) Removes a parameter name from this collection.void
reset()
Resets all parameters to their initial values.void
setCheckbox
(String name, boolean state) Sets the value of the specified checkbox parameter.void
setCheckbox
(String name, String value, boolean state) Sets the value of the specified checkbox parameter.void
setParameter
(String name, com.meterware.httpunit.protocol.UploadFileSpec[] files) Sets the multiple values of a file upload parameter in a web request.void
setParameter
(String name, File file) Sets the single value of a file upload parameter in this form.void
setParameter
(String name, String value) Sets the value of a parameter in this form.void
setParameter
(String name, String[] values) Sets the multiple values of a parameter in this form.submit()
Submits this form using the web client from which it was originally obtained.submit
(SubmitButton button) Submits this form using the web client from which it was originally obtained.submit
(SubmitButton button, int x, int y) Submits this form using the web client from which it was originally obtained.Submits this form using the web client from which it was originally obtained, ignoring any buttons defined for the form.protected WebResponse
submitRequest
(String event, WebRequest request) submit the given event for the given requestvoid
toggleCheckbox
(String name) Toggles the value of the specified checkbox parameter.void
toggleCheckbox
(String name, String value) Toggles the value of the specified checkbox parameter.Methods inherited from class com.meterware.httpunit.WebRequestSource
doEvent, doEventScript, getAttribute, getBaseResponse, getBaseURL, getClassName, getCurrentFrameContents, getDestination, getDOMSubtree, getElement, getFragmentIdentifier, getFrame, getHTMLPage, getID, getName, getNode, getPageFrame, getParentDelegate, getRelativeURL, getScriptingHandler, getTagName, getTarget, getText, getTitle, handleEvent, isSupportedAttribute, loadDestinationParameters, removeAttribute, setAttribute, setDestination, setTargetAttribute, submitRequest
-
Field Details
-
MATCH_NAME
Predicate to match a link's name.
-
-
Method Details
-
submit
Submits this form using the web client from which it was originally obtained.- Throws:
IOException
SAXException
-
submit
Submits this form using the web client from which it was originally obtained. Will usually return the result of that submission; however, if the submit button's 'onclick' or the form's 'onsubmit' event is triggered and inhibits the submission, will return the updated contents of the frame containing this form.- Throws:
IOException
SAXException
-
submit
Submits this form using the web client from which it was originally obtained. Will usually return the result of that submission; however, if the submit button's 'onclick' or the form's 'onsubmit' event is triggered and inhibits the submission, will return the updated contents of the frame containing this form.- Throws:
IOException
SAXException
- Since:
- 1.6
-
submitNoButton
Submits this form using the web client from which it was originally obtained, ignoring any buttons defined for the form.- Throws:
SAXException
IOException
- Since:
- 1.6
-
submitRequest
protected WebResponse submitRequest(String event, WebRequest request) throws IOException, SAXException Description copied from class:WebRequestSource
submit the given event for the given request- Overrides:
submitRequest
in classWebRequestSource
- Parameters:
event
-request
-- Returns:
- the response for the submitted Request
- Throws:
IOException
SAXException
-
getMethod
Returns the method defined for this form. -
getAction
Returns the action defined for this form. -
hasParameterNamed
Returns true if a parameter with given name exists in this form. -
hasParameterStartingWithPrefix
Returns true if a parameter starting with a given name exists, -
getButtons
Returns an array containing all of the buttons defined for this form. -
getButton
-
getButtonWithID
Convenience method which returns the button with the specified ID. -
getSubmitButtons
Returns an array containing the submit buttons defined for this form. -
getSubmitButton
Returns the submit button defined in this form with the specified name. If more than one such button exists, will return the first found. If no such button is found, will return null. -
getSubmitButton
Returns the submit button defined in this form with the specified name and value. If more than one such button exists, will return the first found. If no such button is found, will return null. -
getSubmitButtonWithID
Returns the submit button defined in this form with the specified ID. If more than one such button exists, will return the first found. If no such button is found, will return null. -
getRequest
Creates and returns a web request which will simulate the submission of this form with a button with the specified name and value. -
getRequest
Creates and returns a web request which will simulate the submission of this form with a button with the specified name. -
getRequest
Creates and returns a web request which will simulate the submission of this form by pressing the specified button. If the button is null, simulates the pressing of the default button. -
getRequest
Creates and returns a web request which will simulate the submission of this form by pressing the specified button. If the button is null, simulates the pressing of the default button.- Parameters:
button
- - the submitbutton to be pressed - may be nullx
- - the x positiony
- - the y position
-
newUnvalidatedRequest
Creates and returns a web request which includes the specified button. If no button is specified, will include the default button, if any. No parameter validation will be done on the returned request and no scripts will be run when it is submitted. -
newUnvalidatedRequest
Creates and returns a web request which includes the specified button and position. If no button is specified, will include the default button, if any. No parameter validation will be done on the returned request and no scripts will be run when it is submitted. -
getParameterValue
Returns the default value of the named parameter. If the parameter does not exist returns null. -
getOptions
Returns the displayed options defined for the specified parameter name. -
getOptionValues
Returns the option values defined for the specified parameter name. -
isMultiValuedParameter
Returns true if the named parameter accepts multiple values. -
getNumTextParameters
Returns the number of text parameters in this form with the specified name. -
isTextParameter
Returns true if the named parameter accepts free-form text. -
isSubmitAsMime
public boolean isSubmitAsMime()Returns true if this form is to be submitted using mime encoding (the default is URL encoding). -
getScriptableObject
-
reset
public void reset()Resets all parameters to their initial values. -
newScriptable
-
getCharacterSet
Returns the character set encoding for this form. -
isFileParameter
Returns true if the named parameter accepts files for upload. -
getParameterNames
Returns an array containing the names of the parameters defined for this form.- Specified by:
getParameterNames
in classWebRequestSource
-
getParameterValues
Returns the multiple default values of the named parameter.- Specified by:
getParameterValues
in classWebRequestSource
-
isReadOnlyParameter
Returns true if the named parameter is read-only. If more than one control exists with the same name, will return true only if all such controls are read-only. -
isDisabledParameter
Returns true if the named parameter is disabled. If more than one control exists with the same name, will return true only if all such controls are read-only. -
isHiddenParameter
Returns true if the named parameter is hidden. If more than one control exists with the same name, will return true only if all such controls are hidden. -
getRequest
Creates and returns a web request which will simulate the submission of this form with an unnamed submit button.- Specified by:
getRequest
in classWebRequestSource
-
newUnvalidatedRequest
Creates and returns a web request based on the current state of this form. No parameter validation will be done and there is no guarantee over the order of parameters transmitted. -
addPresetParameter
Records a parameter defined by including it in the destination URL. Ignores any parameters whose name matches a form control.- Specified by:
addPresetParameter
in classWebRequestSource
-
getEmptyParameterValue
- Specified by:
getEmptyParameterValue
in classWebRequestSource
-
recordParameters
public void recordParameters(com.meterware.httpunit.protocol.ParameterProcessor processor) throws IOException Iterates through the parameters in this holder, recording them in the supplied parameter processor.- Throws:
IOException
-
removeParameter
Removes a parameter name from this collection. -
setParameter
Sets the value of a parameter in this form.- Parameters:
name
- - the name of the parametervalue
- - the value of the parameter
-
setParameter
Sets the multiple values of a parameter in this form. This is generally used when there are multiple controls with the same name in the form. -
setParameter
Sets the multiple values of a file upload parameter in a web request. -
setParameter
Sets the single value of a file upload parameter in this form. A more convenient way to do this than usingsetParameter(String,com.meterware.httpunit.protocol.UploadFileSpec[])
- Since:
- 1.6
-
toggleCheckbox
Toggles the value of the specified checkbox parameter.- Parameters:
name
- the name of the checkbox parameter- Throws:
IllegalArgumentException
- if the specified parameter is not a checkbox or there is more than one control with that name.- Since:
- 1.5.4
-
toggleCheckbox
Toggles the value of the specified checkbox parameter.- Parameters:
name
- the name of the checkbox parametervalue
- of the checkbox parameter- Throws:
IllegalArgumentException
- if the specified parameter is not a checkbox or if there is no checkbox with the specified name and value.- Since:
- 1.6
-
setCheckbox
Sets the value of the specified checkbox parameter.- Parameters:
name
- the name of the checkbox parameterstate
- the new state of the checkbox- Throws:
IllegalArgumentException
- if the specified parameter is not a checkbox or there is more than one control with that name.- Since:
- 1.5.4
-
setCheckbox
Sets the value of the specified checkbox parameter.- Parameters:
name
- the name of the checkbox parametervalue
- of the checkbox parameterstate
- the new state of the checkbox- Throws:
IllegalArgumentException
- if the specified parameter is not a checkbox or if there is no checkbox with the specified name and value.- Since:
- 1.6
-
getControlWithID
Returns the form control which is part of this form with the specified ID. -
getParameter
get the form parameter with the given name- Parameters:
name
-- Returns:
- the form parameter with this name
-