Webtest WebTest GitHub Home

Core Step clickButton

Description

This step is used to locate a form button and then click it.

Currently tested and thus officially supported are the following variations of buttons:

<input type="submit" .../>
<input type="image" .../>
<input type="button" .../>
<input type="reset" .../>
<button .../>
If neither 'label', 'name', 'htmlid', nor 'xpath' is specified, the first button found is clicked (in document order, looking first in the current form, if any).

Parameters

description
Required? no
The description of this test step.
fieldIndex
Required? no, default is 0
The index (starting with 0) of the button to click within the buttons having the specified label and/or name. Useful for instance to distinguish two buttons having the same name.
htmlId
Required? no
The html id of the button to click.
label
Required? no
The label of the button to click. This is the text representation for a text button or the alt attribute for an image button
name
Required? yes/no
The NAME attribute for the button of interest. Name has lower precedence than htmlId.
password
Required? no
A password that can be provided for pages that require basic authentication. Required if username is specified.
save
Required? no
A shorthand: save='prefixName' is the same as savePrefix='prefixName' saveResponse='true'.
savePrefix
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.
saveResponse
Required? no
Whether to make a permanent copy of received responses. Overrides the default value set in the <config> element.
username
Required? no
A username that can be provided for pages that require basic authentication. Typically only needed on the first step of any webtest accessing a secure site. Required if password is specified.
x
Required? no
Optional X coordinate of click within an image button. If set, Y coordinate must also be set.
xpath
Required? no
The xpath of the button to click.
y
Required? no
Optional Y coordinate of click within an image button. If set, X coordinate must also be set.

Inline Text

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

Required? no
Alternative way to set the 'label' attribute.

Details

The most simple usage of <clickButton> is to submit a simple HTML form back to the server. Consider the following HTML form snippet:

HTML
...
<form method="postaction="formTest">
  <br/>Text:
  <input type="textname="field1value="" />
  <input type="submitname="doIt" />
</form>
...

The following test code sets a value for the input field and submits the form. It assumes that the form is shown again with the input field echoing the previously entered value:

clickButton 1
...
<setInputField description="Set the input field"
  name="field1value="My simple value" />

<clickButton description="Submit the simple formname="doIt" />

<verifyInputField description="Check echo of previous input"
  name="field1value="My simple value" />
...

A more complex sample uses the selectForm step to select a form in which the submit button shall be located. This could be helpful if all forms on a page have a submit button called "send". See the following HTML code:

HTML
...
<form name="form1action="formTest?mode=YYYY">
  <br/> Text:
  <input type="textname="field1value=""/>
  <input type="submitname="doIt"/>
</form>

<form name="form2action="formTest?mode=XXXX">
  <br/> Text:
  <input type="textname="field1value=""/>
  <input type="submitname="doIt" />
</form>
...

The submit button in the second form can be located using the following test step:

clickButton 2
...
<selectForm name="form2"/>
<clickButton description="Submit the simple formname="doIt"/>
...

For cases where a form has many buttons that can't be easily differentiated, it is possible to resolve the ambiguity by using the index property. This specifies which instance of the button appearing in the form shall be taken. The following example shows how to click the second button of the form:

HTML
...
<form name="form1action="formTest?mode=YYYY">
  Text:
  <input type="textname="field1value=""/>
  <input type="submitname="doItvalue="doItThisWay"/>
  <input type="submitname="doItvalue="doItThisOtherWay" />
</form>
...

clickButton 3
...
<clickButton description="Submit the simple formname="doItfieldIndex="1"/>
...

Note: The value must be "1" in order to specify the 2nd button. It has the index "1" whereas the first button has the index "0".