Object Model Reference for GUI Testing > Overview > Understanding Basic VBScript Syntax > Using Variables

Using Variables

You can specify variables to refer to test objects or store simple values. After defining a variable to refer to a test object, you can use the variable instead of the entire object hierarchy in other statements. Using variables in this way makes your statements easier to read and to maintain.

Set statements

To specify a variable refer to an object, use the Set statement, with the following syntax:

Set ObjectVar = ObjectHierarchy

In the example below, the Set statement specifies the variable UserEditBox to store the full Browser.Page.WebEdit object hierarchy for the username edit box. The Set method then enters the value John into the username edit box, using the UserEditBox variable:

Set UserEditBox = Browser("Mercury Tours").Page("Mercury Tours").WebEdit("username")

UserEditBox.Set "John"

Back to top

Simple values

Do not use the Set statement to specify a variable containing a simple value (such as a string or a number). The example below shows how to define a variable for a simple value.

MyVar = Browser("Mercury Tours").Page("Mercury Tours").WebEdit("username").GetTOProperty("type")

Back to top

Dim statement

You can also use the Dim statement to declare variables of other types, including strings, integers, and arrays. This statement is not mandatory, but you can use it to improve the structure of your test or component. In the following example, the Dim statement is used to declare the passengers variable, which can then be used in different statements within the current action.

Dim passengers

passengers = Browser("Mercury Tours").Page("Find Flights").WebEdit("numpassengers").GetROProperty("value")

Back to top