Canoo Webtest WebTest Canoo

Extension Step forceInputFieldAttribute


Sets (or removes) the attribute value of a selected input field. An example usage would be to enable a disabled input field (perhaps to mimic some unsupported JavaScript).


Required? yes
The name of the attribute of interest, e.g. "disabled" or "checked".
Required? yes
The value to set for the attribute of interest; causes the attribute to be removed if set to the empty string (i.e. "").
Required? yes
The value to use when setting the field of interest.
Required? no
The description of this test step.
Required? no, default is the first field found that matches criteria
The index of the field of interest (starting at 0) if more than one field matches criteria. Ignored if htmlId or xpath is used.
Required? yes/no
The text of the label field associated with the input field of interest. One of forLabel, htmlId, name, or xpath is required.
Required? no, default is the last form selected using 'selectForm', otherwise searches all forms
The name of the form containing the field of interest. Ignored if htmlId is used.
Required? yes/no
The id of the input field of interest. One of forLabel, htmlId, name, or xpath is required.
Required? yes/no
The name of the input field of interest. One of forLabel, htmlId, name, or xpath is required.
Required? no
A shorthand: save='prefixName' is the same as savePrefix='prefixName' saveResponse='true'.
Required? no, default is the 'savePrefix' parameter as specified in <config>.
A name prefix can be specified for making a permanent copy of received responses. A unique number and the file extension (depending on the MIME-Type) will be appended. The resultpath attribute of the <config> element is used for determining the location of the saved result.
Required? no
Whether to make a permanent copy of received responses. Overrides the default value set in the <config> element.
Required? no, default is input
The name of the tag of interest, e.g. "input" or "select".
Required? yes/no
The xpath of the input field of interest. One of forLabel, htmlId, name, or xpath is required.

Inline Text

The inline text is all the text between the start tag ( <forceInputFieldAttribute> ) and the end tag ( </forceInputFieldAttribute> ), including blanks, tabs or newlines. Using a pair of start/end tags ( <forceInputFieldAttribute> </forceInputFieldAttribute> ) has not the same behavior than the seemingly equivalent empty element tag ( <forceInputFieldAttribute/> )! See this issue for an example.

Required? no
An alternative to the attribute value for e.g. large TextAreas.


Consider the following HTML form:

<title>InputField Attribute Test Page</title>
<script type="text/javascript">
function checkEmpty(button, element) {
  if (element.value == "") button.disabled=true;
  else button.disabled=false;
// -->
<h1>Form 2</h1>
<form action="dummy.html" >
    Enter Value (auto checks): <input name="value2onkeyup="checkEmpty(button2, this)"><br>
    <input type="submitvalue="Click Mename="button2id="button2disabled="true">

This page contains some JavaScript validation. We would like to use the storeInputFieldAttribute step to check that the validation is working. When the form is first loaded, the "Click Me" button should be disabled as the "value1" field is empty. We can then place some content into the field. However because the onkeyup JavaScript event is not supported, we note that the "Click Me" button is still disabled. We can use the <forceInputFieldAttribute> to force the button to become enabled. For the enabled attribute, we need to remove the "disabled" attribute to enable the button. We do this by setting the "attributeValue" to the empty string "". Here is the script code:

forceInputFieldAttribute Example
<webtest name="testInputFieldAttributeSteps: Show usage of forceInputFieldAttribute step using disabled attribute">
    <config ...>
        <invoke ...>
        <verifytitle description="check we are on the test pagetext="InputField Attribute Test Page" />
        <storeInputFieldAttribute propertyName="isDisabled2aname="button2attributeName="disabled"/>
        <verifyProperty description="check if button is disabledname="isDisabled2atext="true"/>
        <clickButton description="Attempt submit but should be ignored as button is disabledname="button2" />
        <verifytitle description="check we are still on the test pagetext="InputField Attribute Test Page" />
        <setInputField description="set field value would enabled button if onkeyup() was supported event in htmlunit"
            name="value2value="someText" />
        <clickButton description="Attempt submit should fail because of onkeyup() limitationname="button2" />
        <verifytitle description="check we are still on the test pagetext="InputField Attribute Test Page" />
        <forceInputFieldAttribute name="button2attributeName="disabledattributeValue=""/>
        <storeInputFieldAttribute propertyName="isDisabled2bname="button2attributeName="disabled"/>
        <verifyProperty name="isDisabled2btext="false"/>
        <clickButton description="Attempt submit should work as button is enabledname="button2" />
        <verifytitle description="check we are now on the dummy pagetext="Dummy" />

See also: the storeInputFieldAttribute step.


Latest build: development
Posted: 19-Jul-2016 17:36

WebTest 3.0 released, featuring upgrades to Java 5, Groovy 1.6, and HtmlUnit 2.4.
The release includes support for maven integration, IDE-integration like for unit tests, capturing of background JavaScript errors, new steps for mouseOver and mouseOut events, better parallel execution of tests and - as usual - lots of handling improvements.
Posted: 5 March 2009

WebTest @ JavaOne
Dierk König presented "Functional testing of web applications: scaling with Java" on Wed May 7, 13:30 at JavaOne 2008 in the Tools and Scripting Languages track.
Posted: 8 May 2008

New WebTest screencast available:
Data Driven WebTest
Posted: 13 November 2007

First WebTest screencast available:
Creating a first Webtest Project

Extend WebTest with Groovy! Groovy in Action is available in every good bookstore.
Groovy in Action
Posted: 29 January 2007