Forum Discussion

rikkilar's avatar
rikkilar
Occasional Contributor
14 years ago

handle log.error message in loop statement and continue execution

Below is sample vbscript code,where I found 3 objects with properties I passed to findallchildren.



only with one object ,i can do successfull action.so in  for loop i need to handle the log.error exception and continue with execution until i get the desired object





dim select1

props=Array("idStr")


values=Array("searchQueryView:content:restrictions:0:operatorItem")


redim select1(20)


select1 = Sys.Process("firefox").Page("*").FindallChildren(props, values, 10)


log.message(ubound(select1))


for i=0 to ubound(select1)


button(i).click



next

  • Hi Rikki,



    You cannot handle errors posted to the test log the same way as exceptions. However, you can handle the OnLogError event to block some errors (if that's what you need). To learn how to do this, please see the Creating an Event Handler for the OnLogError Event help topic.



    However, it seems to me that you can actually avoid this if you specify more precise search criteria for the object (e.g. include the Enabled, Visible or VisibleOnScreen properties in the list of properties used for objects recognition). Just calling the Click method on random objects to cause errors is not a very reliable practice.
  • rikkilar's avatar
    rikkilar
    Occasional Contributor
    The problem is I am not able get unique idenfication with various combinations I choosen.



    so i need a solution where i can say by doing this 100% sure I get unique identification.



    thats the reason i was asking to handle the errors while looping for object which throws exception until i get right object.






  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Since this is a web object, try using the innerText property in combination with the idStr.  



    Something you can try to do is utilize NameMapping and Aliasing.  With NameMapping, you can use the option of "Required Children" to differentiate objects by whether or not they have specific child objects.