Forum Discussion

marinb's avatar
marinb
Contributor
9 years ago

Object property does not exist right after it passes an exist check?

Given the following piece of code in our script:   Sys.Refresh(); if (aqObject.IsSupported(Sys.Desktop.ActiveWindow(), "MappedName")) { if (Sys.Desktop.ActiveWindow().MappedName != null) //FA...
  • ghuff2's avatar
    9 years ago

    Well the only place I can think the issue would be is when calling the ActiveWindow() method. You aren't technically checking the same object since you are grabbing a new object with each call to the ActiveWindow() method. That method returns either a Window object or an empty stub object if no top-level window is found. In your code it must return a Window object in the first check then during the second check for whatever reason something changed and TestComplete doesn't think there's any top-level windows so it returns an empty stub object which doesn't have the MappedName property.

     

    I couldn't reproduce the issue myself, but my suggestion is that you return the results for the ActiveWindow() method into a variable, then reference that same variable. So I'd change your code to this:

     

    Sys.Refresh();
    activeWindow = Sys.Desktop.ActiveWindow()
    if (aqObject.IsSupported(activeWindow, "MappedName"))
    {
        if (activeWindow.MappedName != '')  //FAILS HERE
        {
           <...snip...> 

    Which BTW, the MappedName property is never null. If you don't have a MappedName for an object it returns an empty string which is different than null.