Forum Discussion

tuggen's avatar
tuggen
New Contributor
10 years ago

WaitProperty("Exists") error message

Hi!



Usually to check if exists any object I use function WaitProperty(...) or direct property Exists. When it doesn't exist it returns False and my test runs further. 

Earlier it worked perfectly. Now sometimes I receive the following error message in the test log during checking with WaitProperty function or Exists property:

'Unable to find the object [myObjectName]. See Additional Information for details.'

In the Additional Information is 'The object with the specified attributes does not exist.' written. It's a strange behaviour. It happens with different controls that don't exists, with buttons, with groupboxes, etc...

What can cause such error?



Thanks,

Alexandra

10 Replies

  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor
    Hi Alexandra,



    I seem to recall having similar issues with certain properties because of the way the waitproperty method works. I wrote a function for you that is similar to what I use. Try it and see how this works for you:





    //JScript example


    var wshell = new ActiveXObject('WScript.Shell');


    var myObject = //your object here


    wshell.popup(waitProperty(myObject,'Your property name here','Your property value here',15000));






    function waitProperty(object,propName,propValue,timeOut){


    timeOut = !timeOut ? 0:timeOut;


    var start = new Date().getTime();


    Indicator.PushText('Waiting for property value...\nTime remaining: ' + parseInt(timeOut / 1000));


    if (object && typeof object == 'object' && aqObject.IsSupported(object,propName)){


     if (object[propName] == propValue){


      return true;


      }


     }


    timeOut -= (new Date().getTime() - start);


    if (timeOut <= 0){


     return false;


     }


    return waitProperty(object,propName,propValue,timeOut);


    }


  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor
    Or you could have read what I posted (before Alexei repeated exactly what I spelled out in code) and realized I had a check to see if the object existed/ properly handled the error with a similar method.
  • sbkeenan's avatar
    sbkeenan
    Frequent Contributor
    Hi Alexandra

     

    It may be that the object is one of the parent objects of the object that you have associated with the WaitProperty(…) statement.  You could try introducing  a delay and testing whether all the objects do indeed exist.

     

    Regards

    Stephen.

  • karkadil's avatar
    karkadil
    Valued Contributor
    Ah, I see, you use Wait methods, but still get the error.



    Check whether you use such constructions



    if (...WaitWindow(..., ,,,).Exists)

    {

      ...Window(..., ...).Click();

    }



    It might happen that you get the error not on the line where Wait method is used, but on another one
  • murugans1011's avatar
    murugans1011
    Regular Contributor
    Hello



    Wait property only works with objects that exists. to handle object not found error refer link

     http://support.smartbear.com/viewarticle/56627/



    if udont want log to be posted error u can enable dispabe log using



    log.Enable=False



    if u r using vbscript thn u can use if object to chek for an object has reference





    if isObject(objectname) then



     objectname.waitproperty(propertyname,propValue,Timeout)

    End if
  • tuggen's avatar
    tuggen
    New Contributor
    Murugan, thanks for the idea with log disabling.



    Gena, Call stack shows, that the line with WaitProperty posts the error. If is causes another line, then Call stack works worng :( I will try to use WaitWindow.. but my window already exists, only spefic control doesn't exist. 



    I am amazed, because such behaviour happens not always. In many cases I have no errors using WaitProperty for the not existing objects... 
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Alexandra,



    In TestComplete, when UI (or special stub) object exists (or existed earlier and was referenced by test code) it always has Exists property. So check of object.WaitProperty("Exists") is useless and can be replaced with just object.Exists.

    The reason of the sporadic error messages in the log in your case may be because the given object might not be created by the tested application yet while your test code already attempts to use it.

    SmartBear pays constant attention to TestComplete's performance, so quite often guys are reporting that they had no problems with their test while using, say, version 9, but started to get 'object not found' error after upgrading to version 10.

    Most often the reason is improved performance of test execution.

    As an example, consider this scenario: your test clicks on some link in the web application, this causes some text (label) to be shown and you need to log the contents of this label.

    Consider this pseudocode:

    page.parentObject.Link.Click

    If (page.parentObject.Label.Exists) Then

      Log.Message(page.parentObject.Label.innerText)

    Else

      Log.Error ...

    End If



    This code will work if your application is fast enough (or test execution is slow enough:) ) and the label object is created almost immediately after the link is clicked.

    Otherwise, you will get the 'object not found' error on this line:

    If (page.parentObject.Label.Exists) Then

    The reason of the error will be that test code tries to get the .Exists property of the object (Label) that is not created yet.

    To avoid the error, correct actions sequence must be like this:

    -- Click the link;

    -- Wait for the target object for some reasonable time period;

    -- Check if the object or its stub (see TestComplete's help for WaitXXX() functions for more details) was created;

    -- Use the object if it was created.



    Using the same pseudocode, the modified test will look like this:

    page.parentObject.Link.Click

    Set oLabel = page.parentObject.WaitLabel(5000) ' wait up to 5 secs for the label to be created

    If (oLabel.Exists) Then

      Log.Message(oLabel.innerText)

    Else

      Log.Error("Label object was not created within 5 seconds")

    End If



    Hope, this will help...
  • tuggen's avatar
    tuggen
    New Contributor
    Alexei, thanks for such detailed answer. I appreciate it very much. :) 



    Probably I forgot to explain my task. I am awaiting that the object doesn't not exist. It should not exist. That's why the mentioned error is so critical for me. I see only one way to resolve my issue - to disable log during this check.  
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Alexandra,



    > Probably I forgot to explain my task.

    Oh, sorry for not been a clairvoyant...

    BTW, it usually helps when people mention at least TestComplete version they are using and what type of application they are testing...



    Nevertheless, if you need to check whether some object exists or not, you should use one of the WaitXXX methods (e.g. WaitProcess(), WaitWindow(), WaitChild(), WaitPanel(), etc. see TC's help for more details) with the timeout parameter set to zero or some small delay (e.g. 500ms) and then check if the sought for object exists or not.

    Pseudocode sample:

    Set w = process.SomeWindow

    Set obj = w.WaitChild("Button_OK", 500)

    If (obj.Exists) Then

      ...

    Else

      ...

    End If