Forum Discussion

douglasv's avatar
douglasv
Occasional Contributor
5 years ago

Validate if object does not exist

Hi everyone I'd like to know if this part of code is the best way to validate if some object does not exist......and if is,  best way to do not waste time to checking it. I don't know it there is a ...
  • tristaanogre's avatar
    tristaanogre
    5 years ago

    Technically speaking, you can't check the "Exists" property of an object that doesn't exist because there would be no object to have an Exists property.  This is why the methods of WaitChild, WaitAliasChild, WaitWindow, WaitProcess, etc., were created.  Instead of the code you have, I'd do the following.

     

    if( (! browseTelaSelecionaControle.WaitAliasChild('Controle15', 1000).Exists)&&
    (! browseTelaSelecionaControle.WaitAliasChild('Controle95', 1000).Exists)){
    Log.Checkpoint("Controls are NOT visible");
    }
    else{
    Log.Error("Controls ARE visible");
    }
    

    This will wait for the control to exist for up to 1 second and, if it doesn't return within that 1 second, it returns a stub object with only the "Exists" property set to False.