com.meterware.httpunit
Class WebForm

java.lang.Object
  |
  +--com.meterware.httpunit.ParameterHolder
        |
        +--com.meterware.httpunit.WebRequestSource
              |
              +--com.meterware.httpunit.WebForm

public class WebForm
extends WebRequestSource

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.


Inner Class Summary
 class WebForm.Scriptable
           
 
Method Summary
protected  void addPresetParameter(String name, String value)
          Records a parameter defined by including it in the destination URL.
 String getAction()
          Returns the action defined for this form.
 String getCharacterSet()
          Returns the character set encoding for this form.
 String getMethod()
          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.
 String[] getParameterNames()
          Returns an array containing the names of the parameters defined for this form.
 String getParameterValue(String name)
          Returns the default value of the named parameter.
 String[] getParameterValues(String name)
          Returns the multiple default values of the named parameter.
 WebRequest getRequest()
          Creates and returns a web request which will simulate the submission of this form with an unnamed submit button.
 WebRequest getRequest(String submitButtonName)
          Creates and returns a web request which will simulate the submission of this form with a button with the specified name.
 WebRequest 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.
 WebRequest getRequest(SubmitButton button)
          Creates and returns a web request which will simulate the submission of this form by pressing the specified button.
 WebRequest 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.
 WebForm.Scriptable getScriptableObject()
          Returns an object which provides scripting access to this form.
 SubmitButton getSubmitButton(String name)
          Returns the submit button defined in this form with the specified name.
 SubmitButton getSubmitButton(String name, String value)
          Returns the submit button defined in this form with the specified name and value.
 SubmitButton[] getSubmitButtons()
          Returns an array containing the submit buttons defined for this form.
 SubmitButton getSubmitButtonWithID(String ID)
          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 isFileParameter(String name)
          Returns true if the named parameter accepts files for upload.
 boolean isMultiValuedParameter(String name)
          Returns true if the named parameter accepts multiple values.
 boolean isSubmitAsMime()
          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.
 void removeParameter(String name)
          Removes a parameter name from this collection.
 void reset()
          Resets all parameters to their initial values.
 void selectImageButtonPosition(SubmitButton imageButton, int x, int y)
          Specifies the position at which an image button (if any) was clicked.
 void setParameter(String name, String value)
          Sets the value of a parameter in this form.
 void setParameter(String name, String[] values)
           
 void setParameter(String name, UploadFileSpec[] files)
          Sets the multiple values of a file upload parameter in a web request.
 
Methods inherited from class com.meterware.httpunit.WebRequestSource
getBaseURL, getDestination, getDOMSubtree, getID, getName, getNode, getTarget, loadDestinationParameters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getMethod

public String getMethod()
Returns the method defined for this form.

getAction

public String getAction()
Returns the action defined for this form.

hasParameterNamed

public boolean hasParameterNamed(String soughtName)
Returns true if a parameter with given name exists in this form.

hasParameterStartingWithPrefix

public boolean hasParameterStartingWithPrefix(String prefix)
Returns true if a parameter starting with a given name exists,

getSubmitButtons

public SubmitButton[] getSubmitButtons()
Returns an array containing the submit buttons defined for this form.

getSubmitButton

public SubmitButton getSubmitButton(String name)
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

public SubmitButton getSubmitButton(String name,
                                    String value)
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

public SubmitButton getSubmitButtonWithID(String ID)
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

public WebRequest 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.

getRequest

public WebRequest 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

public WebRequest getRequest(SubmitButton button)
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

public WebRequest 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. If the button is null, simulates the pressing of the default button.

getParameterValue

public String getParameterValue(String name)
Returns the default value of the named parameter. If the parameter does not exist returns null.

getOptions

public String[] getOptions(String name)
Returns the displayed options defined for the specified parameter name.

getOptionValues

public String[] getOptionValues(String name)
Returns the option values defined for the specified parameter name.

isMultiValuedParameter

public boolean isMultiValuedParameter(String name)
Returns true if the named parameter accepts multiple values.

getNumTextParameters

public int getNumTextParameters(String name)
Returns the number of text parameters in this form with the specified name.

isTextParameter

public boolean isTextParameter(String name)
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).

reset

public void reset()
Resets all parameters to their initial values.

getScriptableObject

public WebForm.Scriptable getScriptableObject()
Returns an object which provides scripting access to this form.

getCharacterSet

public String getCharacterSet()
Returns the character set encoding for this form.

isFileParameter

public boolean isFileParameter(String name)
Returns true if the named parameter accepts files for upload.

getParameterNames

public String[] getParameterNames()
Returns an array containing the names of the parameters defined for this form.
Overrides:
getParameterNames in class WebRequestSource

getParameterValues

public String[] getParameterValues(String name)
Returns the multiple default values of the named parameter.
Overrides:
getParameterValues in class WebRequestSource

getRequest

public WebRequest getRequest()
Creates and returns a web request which will simulate the submission of this form with an unnamed submit button.
Overrides:
getRequest in class WebRequestSource

addPresetParameter

protected void addPresetParameter(String name,
                                  String value)
Records a parameter defined by including it in the destination URL.
Overrides:
addPresetParameter in class WebRequestSource

selectImageButtonPosition

public void selectImageButtonPosition(SubmitButton imageButton,
                                      int x,
                                      int y)
Specifies the position at which an image button (if any) was clicked.

removeParameter

public void removeParameter(String name)
Removes a parameter name from this collection.

setParameter

public void setParameter(String name,
                         UploadFileSpec[] files)
Sets the multiple values of a file upload parameter in a web request.

setParameter

public void setParameter(String name,
                         String value)
Sets the value of a parameter in this form.

setParameter

public void setParameter(String name,
                         String[] values)