Forum Discussion
tristaanogre
14 years agoEsteemed Contributor
Amy,
The problem is in the following logic block.
There are two problems with this.
First of all, if wndNotepad does not exist, you cannot call the Exists property of it. The code you're using to find the child object is simply the "Window" method which assumes, ahead of time, the object exists. This is probably why you're getting the "object not found" error because you cannot call "Exists" on an non-existant object.
Secondly, even if that worked, if the object does not exist, you cannot capture a picture of it. Log.Picture requires an object to be present and exisiting so you cannot capture a screenshot of it.
Let me suggest a different piece of code for this.
The FindChild is specifically designed for this purpose. If it finds the object you're looking for, it returns the object. If it does not find the object, it returns an "empty" or stub object that has an Exists property equal to false.
The problem is in the following logic block.
Set wndNotepad = Eval("p." & strObjName)
If wndNotepad.Exists then
Log.Message("Ok")
End If
Log.Picture wndNotepad, "Notepad window", wndNotepad.FullName
End Sub
There are two problems with this.
First of all, if wndNotepad does not exist, you cannot call the Exists property of it. The code you're using to find the child object is simply the "Window" method which assumes, ahead of time, the object exists. This is probably why you're getting the "object not found" error because you cannot call "Exists" on an non-existant object.
Secondly, even if that worked, if the object does not exist, you cannot capture a picture of it. Log.Picture requires an object to be present and exisiting so you cannot capture a screenshot of it.
Let me suggest a different piece of code for this.
Sub NotepadTest
Dim p, wndNotepad
Dim PropArray
Dim ValuesArray
PropArray = Array("wndClass", "wndCaption")
ValuesArray = Array("Notepad", "* - Notepad")
Set p = Sys.Process("notepad")
Set wndNotepad = p.FindChild(PropArray, ValuesArray, 1)
If wndNotepad.Exists then
Log.Message("Ok")
Else
Log.Warning("The notepad window was not found")
End If
End Sub
The FindChild is specifically designed for this purpose. If it finds the object you're looking for, it returns the object. If it does not find the object, it returns an "empty" or stub object that has an Exists property equal to false.