Java – QTP Script | how to get object of some open window just using its class type, like JavaWindow, without specifying its title

javaqtpvbscript

I want my code to b as dynamic as possible, here is my 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

    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!

Best Answer

Through descriptive programming, you can catch your JavaWindow on its index property:

Set myJavaWindow = JavaWindow("index:=0")

The 0 can be parameterised of course.


Edit after comment: To make your second example work:

Dim myJW, i
For i = 0 to 1023
    Set myJW = JavaWindow("index:=" & i)
    If not myJW.Exist Then Exit For

    msgbox "Text for JavaWindow " & i & ": " & myJW.GetRoProperty("label")
Next

To match on a JavaWindow with a certain label, you can also use Descriptive Programming like:

myLabel = "Xyzzy!"
If JavaWindow("label:=" & myLabel, "index:=0").exist Then
    msgbox "Woei! A Javawindow with label '" & myLabel & "' exists!"
End if
Related Topic