Webtest WebTest GitHub Home

Core Step setSelectField

Description

Provides the ability to update select fields in HTML forms.

The select field to set will be determined by finding the appropriate form followed by finding the appropriate field on that form unless an xpath or html id is provided for a direct access. Once the appropriate select field is chosen the appropriate option within the field to set is determined.

Form Selection: In many cases, your page will only have one form - that form will be used - you don't need to worry about trying to select the form. For tricky cases, you might need to do extra work to select the appropriate form. See the setRadioButton step for further details on how to do this.

Field Selection: in many cases, only one field will match the name of the field you are interested in. In these cases, you don't need to worry about the remaining details for selecting fields. For tricky cases, you might need to do extra work to select the appropriate field. See the setInputField step for further details on how to do this. If xpath or htmlId identifies a select, then one of value, text, or optionIndex is required to identify the option within the select.

Option Selection: the option to set is selected as follows:

If the xpath value identifies an option, set that option.
If the htmlId value identifies an option, set that option.
If an option in the chosen select field matches by value, set that option.
If an option in the chosen select field matches by its text, set that option.
If an option in the chosen select field matches by its optionIndex, set that option.

NOTE: A regular expression can be specified if a particular option is selected by its text.

Parameters

description
Required? no
The description of this test step.
fieldIndex
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.
forLabel
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.
formName
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.
htmlId
Required? yes/no
The id of the input field of interest. One of forLabel, htmlId, name, or xpath is required.
multiselect
Required? false, default is false
Specifies whether multiple selections are allowed. Unless set to true, every setselect overrides the value of preceding calls.
name
Required? yes/no
The name of the input field of interest. One of forLabel, htmlId, name, or xpath is required.
optionIndex
Required? yes/no
The index of the option to select (i.e. the position of the option in the select starting with 0). One of text, value or optionIndex is required.
password
Required? no
A password that can be provided for pages that require basic authentication. Required if userName is specified.
regex
Required? no, default is false
Specifies whether the option text represents a regular expression.
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 any received responses. Only needed if setting the select field invokes JavaScript which causes the browser to move to another page.
saveResponse
Required? no
Whether to make a permanent copy of any received responses. Overrides the default value set in the <config> element. Only needed if setting the select field invokes JavaScript which causes the browser to move to another page.
text
Required? yes/no
The text of the option to select (i.e. the text nested in the option tag. One of text, value or optionIndex is required.
userName
Required? no
A username that can be provided for pages that require basic authentication. Only needed if setting the select field invokes JavaScript and causes the page to move to a secure page. Required if password is specified.
value
Required? yes/no
The value of the option to select (i.e. the value of the "value" attribute of a select element). One of text, value or optionIndex is required.
xpath
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 ( <setSelectField> ) and the end tag ( </setSelectField> ), including blanks, tabs or newlines. Using a pair of start/end tags ( <setSelectField> </setSelectField> ) has not the same behavior than the seemingly equivalent empty element tag ( <setSelectField/> ).

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

Details

See the following example for selecting a single entry from a list by its value.

setSelectField 1
<webtest name="Select an entry in a list box">
  <config ... />
  <steps>
    <invoke ... />
        <setSelectField
            description="Set 1st MultiSelect value to v1"
            name="MultiSelect"
            value="v1" />
        <setSelectField
            description="Set 2nd MultiSelect value to v2 via option text"
            name="MultiSelect"
            text="Text for v2" />
        <clickButton
            description="submit the form to check parameter setting/resetting"
            label="doIt"/>
        <verifySelectField
            description="check 1st selection"
            name="MultiSelect"
            value="v1" />
        <verifySelectField
            description="check 2nd selection"
            name="MultiSelect"
            value="v2" />
  </steps>
</webtest>

The next example illustrates the selection of multiple values.

setSelectField 2
<webtest name="Select 2 entries in a multi select list box">
  <config ... />
  <steps>
    <invoke ... />
        <setSelectField
            description="Set 1st MultiSelect value to v1"
            name="MultiSelect"
            value="v1"
            multiselect="true" />
        <setSelectField
            description="Set 2nd MultiSelect value to v2"
            name="MultiSelect"
            value="v2"
            multiselect="true" />
        <clickButton
            description="submit the form to check parameter setting/resetting"
            label="doIt"/>
        <verifySelectField
            description="check 1st value"
            name="MultiSelect"
            value="v1" />
        <verifySelectField
            description="check 2nd value"
            name="MultiSelect"
            value="v2" />
  </steps>
</webtest>

Note: If values are selected with multiselect="true" existing selections are preserved. This is also true for items pre-selected in the HTML page using <option value="..." selected>.

See also: the verifySelectField and selectForm steps.