Forum Discussion

sak's avatar
sak
Occasional Contributor
14 years ago

Unable to find the object

Depending on whether or not a user has previously logged in to a remote website's application, either of 2 web objects will be present.  I want to determine whether or not the user was already logged in so I can do different testing.  Below is the code that I tried to use, looking for one of the 2 possible web objects:



  if (Sys.Process("iexplore", 2).Page("https://192.168.1.100/abc/defg/login.do?action=secure").Frame("navigation").Exists)

  {

    Log.Event("new login");

  }

  else

  {

    Log.Event("existing login");

  }



If the "navigation" frame does not exist, I receive an error [Unable to find the object Frame("navigation")].  How should I be testing for something that may or may not exist?  I've tried WaitFrame, but that also generates an error message.  It seems like this is something simple that testers would want to do.  What am I missing here?  Any help greatly appreciated - thank you!

3 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    The problem is that if the Frame("navigation") object doesn't exist as an object, you can't call the "Exists" property... how can you check the property of an object when the object doesn't exist?



    So... you need to trick it... That's what the WaitFrame method should be doing.  I'm curious as to what error you got with it.



    Here is how I would implement your code using WaitFrame



    if (Sys.Process("iexplore", 2).Page("https://192.168.1.100/abc/defg/login.do?action=secure").WaitFrame("navigation", 10000).Exists)

      {

        Log.Event("new login");

      }

      else

      {

        Log.Event("existing login");

      }




    Here's the documentation on WaitFrame http://smartbear.com/support/viewarticle/12753/



    Does this help?


  • sak's avatar
    sak
    Occasional Contributor
    Thank you, that does exactly what I want!



    From your example, I saw that I was misusing WaitFrame.  Being new to TestComplete, I did not understand how to use WaitFrame and was unable to find any examples that I could relate to.  I did something like the following to get the error message (it may have been "object expected"):



    //BAD CODE

    if
    WaitFrame(Sys.Process("iexplore",
    2).Page("https://192.168.1.100/abc/defg/login.do?action=secure")."navigation",
    1000).Exists)

    //BAD CODE



    Many thanks.  :)