If...Then...Else Statement

Relevant for: GUI actions, scripted GUI components, and function libraries

The If...Then...Else statement instructs UFT to perform a statement or a series of statements based on specified conditions. If a condition is not fulfilled, the next Elseif condition or Else statement is examined. It has the following syntax:

If condition Then
	statement
ElseIf condition2 Then
	statement
Else
	statement
End If

Item

Description

condition

Condition to be fulfilled.

statement

Statement to be perform.

Example: In the following example, if the number of passengers is fewer than four, UFT closes the browser:

passengers = Browser("Mercury Tours").Page("Find Flights").WebEdit("numpassengers").GetROProperty("value")
If (passengers < 4) Then
	Browser("Mercury Tours").Close
Else
	Browser("Mercury Tours").Page("Find Flights").Image("continue").Click 69,5
End If

The following example uses If, ElseIf, and Else statements to check whether a value is equal to 1, 2, or a different value:

value = 2
If value = 1 Then
   msgbox "one"
ElseIf value = 2 Then
   msgbox "two"
Else
   msgbox "not one or two"
End If