Search code examples
qtphp-uft

Ordinal identifier issue - QTP


There are 4 static text on page

jWin.JavataStaticText("toolkit class:=nz.vdi","index:=0").GetROProperty("attached text")
jWin.JavataStaticText("toolkit class:=nz.vdi","index:=1").GetROProperty("attached text")
jWin.JavataStaticText("toolkit class:=nz.vdi","index:=2").GetROProperty("attached text")
jWin.JavataStaticText("toolkit class:=nz.vdi","index:=3").GetROProperty("attached text")

When I run this script then I get output in following way

VM
Host
Host Server
Storage Volume

When I run the same script after 4-5 mins then I output sequence get changed

Host Server
VM
Storage Volume
Host

Why is it happening? Due to this problem I am not able to perform expected task


Solution

  • The Index selector is the last fall-back that UFT uses when it can't uniquely identify an object. If you have a better way to identify the object (e.g. by using the "attached text" property) you should used that.

    Basically what Index means is "from the set of objects described by this description return the Nth one" so if UFT gets the objects in a different order you will get different objects for the same Index.

    I'm not familiar with Java so I don't know what order the objects are returned. Also I don't know what your use-case is but I'm pretty sure you can find a better way to verify your conditions.

    One thing that may be helpful is using the Location selection property which depends on the relative location of the objects and may be more consistent in your case. The location selector orders objects first by their x coordinate and then by y.

    For i = 0 to 3
      jWin.JavataStaticText("toolkit class:=nz.vdi","Location:=" & i).GetROProperty("attached text")
    Next