Micro Focus QTP (UFT) Forums
Object not found when creating an object during runtime - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Object not found when creating an object during runtime (/Thread-Object-not-found-when-creating-an-object-during-runtime)



Object not found when creating an object during runtime - riechan - 07-23-2012

Hi guys! Can anyone help me with my code? I'm trying to create an object (java textfield) during runtime and input something to that field using the following code:

Code:
            Set txtSearchField = Description.Create()
                txtSearchField("Class Name").Value = "JavaEdit"
            Set objSearchField = objWindow.ChildObjects(txtSearchField)
            
            If valReqdObjClass = "JavaEdit" Then
                objWindow.JavaEdit(txtSearchField).Set valReqdObj
            End If

but the thing is, when I call this code:

Code:
MsgBox objSearchField(0).GetROProperty("attached text")

it always returns nothing. Also, I cannot access the object when I am already trying to input something to it (QTP always returns that object cannot be found). Is there something wrong in the way that I created the object?? Help anyone?


RE: Object not found when creating an object during runtime - Tarik Sheth - 07-23-2012

Hello,

Add more properties to txtSearchField
I think you can use objSearchField as well
Can you pleas try

Code:
objWindow.objSearchField(txtSearchField).Set valReqdObj

Let us know how it goes.


RE: Object not found when creating an object during runtime - riechan - 07-24-2012

Hi Tarik!

Actually, the txtSearchField description for the JavaEdit text box is found in several forms (all of them are search forms), meaning, that this particular text box will differ in its attached text and its developer name for each form. So, I don't think I can add any more specific properties. Although I did find some sort of workaround though:

Code:
            Set txtSearchField = Description.Create()
                txtSearchField("Class Name").Value = "JavaEdit"
            Set objSearchField = objWindow.ChildObjects(txtSearchField)

            strAttachedText = objSearchField(0).GetROProperty("attached text")
            strDeveloperName = objSearchField(0).GetROProperty("developer name")

            ' Input the value into the search field
            If strDeveloperName <> "" Then
                objWindow.JavaEdit("developer name:=" & strDeveloperName).Set valReqdObj
            ElseIf strAttachedText <> "" Then
                objWindow.JavaEdit("attached text:=" & strAttachedText).Set valReqdObj
            End If

Also, when I tried doing your suggestion, I encountered an "Unspecified error" runtime error:

Code:
            Set txtSearchField = Description.Create()
                txtSearchField("Class Name").Value = "JavaEdit"
            Set objSearchField = objWindow.ChildObjects(txtSearchField)

            strAttachedText = objSearchField(0).GetROProperty("attached text")
            strDeveloperName = objSearchField(0).GetROProperty("developer name")

            ' Input the value into the search field
            If strDeveloperName <> "" Then
                objWindow.objSearchField(txtSearchField).Set valReqdObj
            ElseIf strAttachedText <> "" Then
                objWindow.JavaEdit("attached text:=" & strAttachedText).Set valReqdObj
            End If