Forum Discussion

cagan's avatar
cagan
Occasional Contributor
3 years ago

How to handle if not finding on objects is not an error

I have a teststep for saving a file. On windows you know how to save as works. It can directly  save or a pop-up window asks you do you want to overwrite with same name. Briefly, a file can be directly saved or it can overwrite. Both option is applicable for me.

 

So i don't want to take en error when save as window is appeared on the screen. Below code takes error like "Cannot obtain the window with the windowclass...." How can i fix the problem? Thank you

 

var saveAsWindow= Saveasobject

if (saveAsWindow.Exists)

{object.clickbutton();

Log.Message("overwritten button is selected.")

}

else

Log.message("overwritten window is not appeared.  Because it is a new file.")

14 Replies

  • React's avatar
    React
    Occasional Contributor

    caganYou may look at this.

    I came to similar problem when I didn't know if window will appear but still I must search for it.
    My solution was to use FindEx method to search the object because it will return Exists property equals false if it will not found it.
    No error will be raised and you can set the timeout so method will be quite fast.

    https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/findex-method.html?sbsearch=findex

    var object = findEx()

    if (object.exists == false) Log.Message('Windows is not here, so no futher operqations needed');
    else {
      Log.Message('Found the window,');
      CloseAdditionalPopup();
    }

    • sonya_m's avatar
      sonya_m
      SmartBear Alumni (Retired)

      Thank for suggestions, everyone!

       

      cagan did you have a chance to look into the latest advice?

    • cagan's avatar
      cagan
      Occasional Contributor

      Hi,

       

      Thank you for the offer.

       

      I tried FindEx() medhot like that. But still it takes error like the object does not exists. Just in case Save As popup object is found FindEx method does it works otherwise it takes object does not exists error. 

      There should be a way to manage cases if different UI screen appears. 

      • React's avatar
        React
        Occasional Contributor

         

        Well,

        I've tried it by myself because I was sure that error should not be raised and it works fine without erros:

         

        cagan 

        Check if your "if" statement ask for property "exists" == false, cuz it's the only property created when object does't exists.