With Statement

Relevant for: GUI actions and scripted GUI components

With statements make your script more concise and easier to read and write or edit by grouping consecutive statements with the same parent hierarchy.

In addition, using With statements might help your script run faster. When running a With statement, UFT identifies the object in the application before running the first statement, but does not re-identify it before running each statement.

On the other hand, this can affect the running of your test if the object referenced by the With statement is refreshed, redrawn, or changed in some way in the application while running the With statement. To instruct UFT to re-identify the object in the application before running the next statement, add a statement that calls the RefreshObject test object operation.

The With statement has the following syntax:

With object
End With




An object or a function that returns an object.


One or more statements to be performed on an object.

Example: You could replace this script:

Window("Flight Reservation").WinComboBox("Fly From:").Select "London"
Window("Flight Reservation").WinComboBox("Fly To:").Select "Los Angeles"
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinList("From").
	Select "19097 LON"
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click

with the following:

With Window("Flight Reservation")
	.WinComboBox("Fly From:").Select "London"
	.WinComboBox("Fly To:").Select "Los Angeles"
	With .Dialog("Flights Table")
		.WinList("From").Select "19097 LON"
	End With 'Dialog("Flights Table")
End With 'Window("Flight Reservation") 

Note: In addition to entering With statements manually, you can also instruct UFT to automatically generate With statements as you record or to generate With statements for an existing test. For more details, see Generate With statements.