Micro Focus QTP (UFT) Forums
QTP Script | how to get object of some open window just using its class type,Java - 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: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: QTP Script | how to get object of some open window just using its class type,Java (/Thread-QTP-Script-how-to-get-object-of-some-open-window-just-using-its-class-type-Java)



QTP Script | how to get object of some open window just using its class type,Java - sophia.sabir - 03-07-2012

I want my code to b as dynamic as possible, here is my code
Code:
Set buttonDesc = Description.Create()
buttonDesc("Class Name").Value = "JavaButton"

Set reqButton = JavaWindow("AKAM Application").ChildObjects(buttonDesc)
text = reqButton(1).GetROProperty("label")
JavaWindow("AKAM Application").JavaButton(text).Click

here, in line 1 and 2, I have declared a property so that i can click on button using its index (1) without specifying its title, I want to do the same for the windows object, where i have to specify the title of the window "AKAM Application". The problem is that i need JavaWindow's parent class some how so that i could get it children and specify the Class Name to be javaWindow and get my desired object, but either QTP does not catch it parent, or there isnt any at all, later is possible case. Is there any way that i can get objects of all opened windows and the specify javaWindow and get my desired window? I have tried following code but it does not work, probably because my application's window does not show "JavaWindow" in its title bar, i'm not sure

Code:
Dim WinDesc
    Set WinDesc = Description.Create
    WinDesc("nativeclass").Value = "JavaWindow"
    Set WinChildren =Desktop.ChildObjects(WinDesc)
    msgbox WinChildren.count
    For i = 0 to WinChildren.Count - 1
       winText = WinChildren(i).GetROProperty("label")
       msgbox winText
    Next

Kindly Help!


RE: QTP Script | how to get object of some open window just using its class type,Java - anil2u - 08-07-2013

Hi,

I am not sure if your first piece of code works either without Object Repository having all the objects with the specific labels you are collecting.

Rather you should have set the object :
Code:
Set buttonDesc = Description.Create()
buttonDesc("Class Name").Value = "JavaButton"

Set reqButton = JavaWindow("AKAM Application").ChildObjects(buttonDesc)
text = reqButton(0).GetROProperty("label") ' the index starts with 0 for the identified objects
If label = "[i]something you are searching for[/i] then
   reqButton(0).click
End If

And coming to your second point, you can very well get your java window, provided its open and you know what are the properties to identify it uniquely. I being unknown to Java add-in would suggest to identify properties such that your window is identified uniquely in two cases
1. When only one java window is open
2. When number of java windows are open
If you didn't get any count at msgbox WinChildren.count, it obviously means that the property is not enough to locate the java windows.

Let me know if this helps

Cheers