Forum Discussion

sshahin's avatar
sshahin
Occasional Contributor
12 years ago

.Exist method or alternative to determine whether an object exists OR not

Is there a way to check if an object exists that will not result in the usual complete runtime failure if the object does not exist?



Thank you

3 Replies

  • denioflavio's avatar
    denioflavio
    Occasional Contributor
    you can also use the wait* methods, for instance:

    waitProcess

    waitWindow

    waitVCLObject, 

    and others...



    Sample:



     if (Sys.Process('tab_veic').Exists) then

    -> throw a log error if the process does not exists.



     if (Sys.waitProcess('tab_veic', 2000).Exists) then

    ->its doesnt throw a log error.

    -> 2000 is the timeout, in miliseconds
  • scott_staniewic's avatar
    scott_staniewic
    Occasional Contributor
    I was wondering the same thing.  If I do an IF Else statement looking to see if an object Exists or not Exists, the code works but always throws an error in the TC logs causing the test to fail.  What can I do to stop the error in the TC logs.... Unable to find the object.



    In my case the object can sometimes have 1 value or another so I'm looking to see if 1 value doesn't exist and if true use the other value.




    if (!(control.VBObject("fraSettings").VBObject("fraBlockExpression")).Exists){



    Log.Message("Value is not fraSettings it is fraSettings_2","",pmNormal,Attr);



    control2 = control.VBObject("fraSettings_2").fraBlockExpression;}



    else



    { Log.Message("Value is fraSettings","",pmNormal,Attr);



    control2 = control.VBObject("fraSettings").fraBlockExpression;}


  • sshahin's avatar
    sshahin
    Occasional Contributor
    Figured it out.



        Set p = Sys.Process(MyProcess)


        Set w = p.FindChild("WndCaption", "FindObjectContainingThisTextInWndCaption", 5)


        If w.Exists Then

          ...

        End If



    The test will not fail if w.Exists is false.



    FindChild method: http://support.smartbear.com/viewarticle/28019/