GetChildren Function




Returns the names of the children of the window declaration for the Classic Agent or the handles of the children of the window in the UI for the Open Agent.


lwChildWins = window.GetChildren ([bInvisible, bNoTopLevel])
Variable Description
Classic Agent
The names of the children of the window declaration.
Open Agent
The handles of the children of the window in the UI.
bInvisible Optional: If TRUE, also returns invisible windows. For the Classic Agent, this is set to FALSE by default. The Open Agent always uses FALSE for this value regardless of what is specified in the script. BOOLEAN.
bNoTopLevel Optional:If TRUE, does not return windows of class MainWin, ChildWin, or BrowserChild. This is set to FALSE by default. The Open Agent always uses FALSE for this value regardless of what is specified in the script. BOOLEAN.


  • GetChildren() does not return body text objects. Body text objects are those that are not contained within an HTML tag.
  • GetChildren returns a list of windows that correspond to the children of the current window.
  • GetChildren includes only those windows that are open at the time of the call. Child windows that are not visible or are off the screen at the time of the call to GetChildren are not included in the list unless you set bInvisible to TRUE.
  • GetChildren does not return window parts.
  • The returned windows are the actual children at runtime, not the children declared in the declarations file. Windows that are declared are returned first, in the order in which they are declared.
  • For the Classic Agent, if a declaration exists for a window, Silk Test Classic returns the identifier of the window; if there is no declaration for the window, Silk Test Classic returns a dynamic instantiation of the window.
  • For the Open Agent, Silk Test Classic returns only the handle of the window.

Open Agent Example

To quickly detect any unwanted structural changes in your application under test (AUT), you can use Silk Test Classic to verify that your AUT correctly displays all included controls. This example describes how you can use the WindowChildren with the GetChildren function of the AnyWin class to compare the actual windows in your AUT with the expected windows. The following code defines a set of windows that are expected to be child windows of Notepad.
		[-] TextField TextField
			[ ] locator "//TextField"
		[-] MenuItem AboutNotepad
			[ ] locator "About Notepad"
		[-]  DialogBox AboutNotepadDialog // This window is only found if the About dialog box is open.
			[ ] locator "About Notepad"
			[-] PushButton OK
				[ ] locator "OK"
The sample script uses the WindowChildren function to retrieve the defined child windows of Notepad, and the GetChildren function to retrieve the actual windows of Notepad. Then the script compares the defined windows with the actual windows and returns the following three lists:
  • Windows that are expected and actually included in Notepad.
  • Windows that were unexpectedly added to Notepad.
  • Windows that are expected but missing from Notepad.
For your application under test, only the first list should include windows.

The entire script looks like the following:

[ ] const wDynamicMainWindow = UntitledNotepad
[ ] 
[-] window MainWin UntitledNotepad
	[ ] locator "/MainWin[@caption='Untitled - Notepad']"
	[ ] 
	[ ] // The working directory of the application when it is invoked
	[ ] const sDir = "C:\"
	[ ] 
	[ ] // The command line used to invoke the application
	[ ] const sCmdLine = "C:\Windows\system32\notepad.exe"
	[ ] 
	[ ] // The list of windows the recovery system is to leave open
	[ ] // const lwLeaveOpenWindows = {?}
	[ ] // const lsLeaveOpenLocators = {?}
	[-] TextField TextField
		[ ] locator "//TextField"
	[-] MenuItem AboutNotepad
		[ ] locator "About Notepad"
	[-]  DialogBox AboutNotepadDialog // this won't be found
		[ ] locator "About Notepad"
		[-] PushButton OK
			[ ] locator "OK"
[ ] 
[ ] 
[-] type WindowVerificationResult is record
	[ ] LIST OF WINDOW verifiedWindows
	[ ] LIST OF STRING newWindows
	[ ] LIST OF WINDOW missingWindows
[ ] 
[ ] 
[-] WindowVerificationResult VerifyWindowChildren(WINDOW windowToVerify)
	[ ] WindowVerificationResult result
	[ ] LIST OF WINDOW childrenDecls = WindowChildren(windowToVerify)
	[ ] LIST OF WINDOW resolved
	[ ] WINDOW w
	[ ] LIST OF WINDOW missingControls
	[-] for each w in childrenDecls
		[-] do
			[ ] ListAppend(resolved, w.resolve({0, true}))
			[ ] ListAppend(result.verifiedWindows, w)
		[-] except
			[ ] ListAppend(result.missingWindows, w)
	[ ] 
	[ ] LIST OF WINDOW actualChildren = windowToVerify.GetChildren()
	[-] for each w in actualChildren
		[ ] INTEGER foundIndex = ListFind(resolved, w)
		[-] if(foundIndex == 0)
			[ ] LIST OF STRING locatorParts = w.GenerateLocator()
			[ ] STRING part
			[ ] STRING combinedLocator = ""
			[-] for each part in locatorParts
				[ ] combinedLocator += part
			[ ] ListAppend(result.newWindows, combinedLocator)
	[ ] 
	[ ] return result
	[ ] 
[ ] 
[-] testcase VerifyNotepad()
	[ ] WindowVerificationResult result = VerifyWindowChildren(UntitledNotepad)
	[ ] Print("Verified Windows: {result.verifiedWindows}")
	[ ] Print("New Windows:      {result.newWindows}")
	[ ] Print("Missing Windows:  {result.missingWindows}")
When replayed, this script returns the following:
[ ] Script windowChildren.t - Passed
[ ] Machine: (local)
[ ] Started: 09:48:37AM on 15-Jul-2015
[ ] Elapsed: 0:00:08
[ ] Passed:  1 test (100%)
[ ] Failed:  0 tests (0%)
[ ] Totals:  1 test, 0 errors, 0 warnings
[ ] 
[-] Testcase VerifyNotepad - Passed
	[ ] Verified Windows: {UntitledNotepad.TextField, UntitledNotepad.AboutNotepad}
	[ ] New Windows:      {/MainWin[@caption='Untitled - Notepad']//Menu[@caption='File'],
	[ ]  /MainWin[@caption='Untitled - Notepad']//Menu[@caption='Edit'],
	[ ]  /MainWin[@caption='Untitled - Notepad']//Menu[@caption='Format'],
	[ ]  /MainWin[@caption='Untitled - Notepad']//Menu[@caption='View'],
	[ ]  /MainWin[@caption='Untitled - Notepad']//Menu[@caption='Help']}
	[ ] Missing Windows:  {UntitledNotepad.AboutNotepadDialog}
This result shows that five windows are included in Notepad, which are not included in the expected set. For future testing, we should include these windows in the expected set. The result also shows that one window, which is included in the expected set, is not included in Notepad. This could have two reasons.
  1. Notepad should include this window, but wrongly does not. In this case, we have found an error in the AUT, and we need to take the appropriate actions.
  2. The window has been deliberately removed from the AUT by an application developer. In this case, we need remove the window from the expected window set.