Forum Discussion

salley's avatar
salley
Frequent Contributor
8 years ago

.exists method

i've a form that has about 100 items and they appear based on some Class, and items could sometimes 50/60 depends on the class code, i want to select if item exists , if not move to next and do the same, i just don't want my script to fail if object not found. is it possible to do it through if then else statement, i'm just not sure what to put in else statement, ex:

if value1.exists then value1.click

if value2.exits then value2.click

and so on

else

End if

End if 

if value 2 not found then my test is failing,,i'm new to this ,,, can somebody help me , i just don't want my test to fail. 

thanks

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    You cannot check the "Exists" property of an object that does not exist...  If you think about it, this makes logical sense.

     

    The best way to check for object existence is to use some variation of a WaitNNN method to retrieve the object first and then check for existance. https://support.smartbear.com/testcomplete/docs/app-objects/common-tasks/waiting-process-or-window-activation.html#WaitMethods

     

    So, your code would be something on the lines of

     

    value1 = parentObject.WaitAliasChild('objectName', -1);

    if value1.exists then value1.click

    value2 = parentObject.WaitAliasChild('objectName', -1);

    if value2.exists then value2.click

     

    Or some such pattern.

    • salley's avatar
      salley
      Frequent Contributor

      Thanks, got it. 

      another query if i have the below code and i don't want my test to fail, i just want to click whatever option i've available on the screen and move on, how do i do that ,,,,,,,,,,

      sTable.Cell(1, 1).Table("conForm_ABCD01").Cell(0, 1).RadioButton("conForm_ABCD01_1").Click
      sTable.Cell(2, 1).Table("conForm_ABCD02").Cell(0, 1).RadioButton("conForm_ABCD02_1").Click
      sTable.Cell(3, 1).Table("conForm_ABCD03").Cell(0, 1).RadioButton("conForm_ABCD03_1").Click
      sTable.Cell(4, 1).Table("conForm_ABCD04").Cell(0, 1).RadioButton("conForm_ABCD04_1").Click
      sTable.Cell(5, 1).Table("conForm_ABCD05").Cell(0, 1).RadioButton("conForm_ABCD05_1").Click
      sTable.Cell(6, 1).Table("conForm_WORK06").Cell(0, 1).RadioButton("conForm_ABCD06_1").Click
      sTable.Cell(7, 1).Table("conForm_ABCD06").Cell(0, 1).RadioButton("conForm_ABCD00_1").Click

       

      lets say i've the above script, but i don't have all the items available on the screen, i just want to click whatever items are available,, Thanks in advance,,,