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 method to check NotExist.
Thank you so much.
var TimeoutValue;
TimeoutValue = Options.Run.Timeout;
Options.Run.Timeout = 1000;
if( (! browseTelaSelecionaControle.Controle15.Exists)&&
(! browseTelaSelecionaControle.Controle95.Exists)){
Log.Checkpoint("Controls are NOT visible");
}
else{
Log.Error("Controls ARE visible");
}
Options.Run.Timeout = TimeoutValue;
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.