Creating a Variable for Captured Data

Capture object information with the Identify Object dialog box. You can then create a variable to represent the captured locator information. To do this, capture an object using the Identify Object dialog box and paste the object information into the script. Use the Console.Write method against the object to retrieve the text held in the object, as shown in the following example:

With _desktop.WPFWindow("my main window")
       Console.Write (carmake)
End With

Alternatively, the following example also works:

<my window variable>.WPFTextBox("@automationId='textBoxSingle'").SetText(carmake)
Console.Write (carmake)

A variable can then be created that represents the result of this statement, which is the text held in the control. Declare the variable using a data type of String, and set the variable to the result of the statement. Once the variable is set, its data can be evaluated, validated, displayed, or used for other test purposes. The following shows a variable set to the value of captured text in a message box.

Dim carmake As String

carmake = window.WPFTextBox("@automationId='textBoxSingle'").GetLineText(0)

MsgBox (carmake, vbOKOnly)

This technique of capturing application information and setting it to a variable can be used on any identifiable object in a test application, such as a window, list box, or button.

In addition to using Console.Write method for this purpose, the Text property may be used.

The code looks similar to the following:

Dim price = browser.DomTextField("@name=txtDealerPrice").Text

The Text property can return all the data from the control. However the Text property is not a member of all Silk Test Workbench objects. Use the Text property for supported objects where there is a possibility of data exceeding the size of the display field.

To capture text from more than one control or an entire screen, use Console.Write. For instance, to retrieve the complete text of a web site, type the following:

For more information about retrieving text for Web sites, see What is the Difference Between textContents, innerText, and innerHtml?