cancel
Showing results for 
Search instead for 
Did you mean: 

Wait for Element until its exists

Contributor

Re: Wait for Element until its exists

Got it. Thanks

Contributor

Re: Wait for Element until its exists

function CheckPropertyExists(ObjPropNameArray:OleVariant,ObjPropValuesArray:OleVariant,DispMsg:OleVariant=nil,Parent:OleVariant=nil,WaitTime:OleVariant=nil,IsLogError:boolean=true):boolean;
var
  objToChk : OleVariant;
  i:integer;
  warningTxt,propName,propVal:string;
begin
  try
    try
        if IsNullNil(DispMsg) then
                DispMsg := 'Waiting for the object to appear on the screen';
      Indicator.Show;
      Indicator.PushText(TidyString(DispMsg));
      objToChk := Utils.CreateStubObject;
      if IsNullNil(Parent) then
      begin
        Parent := LOTS_Main_GetLotsParentObj;
        if not Parent.exists then exit;
      end;    
      
      if IsNullNil(WaitTime) then
      begin
        WaitTime := Project.Variables.WaitTime;
      end
      else
        WaitTime := VarToInt(WaitTime);    
      
     for  i : = 0 to  WaitTime/1000 do
     begin
        if not Parent.exists then break;
        objToChk := Parent.FindChild(ObjPropNameArray,ObjPropValuesArray,1000,false);
        Parent.Refresh;      
        if ((objToChk.Exists) and (objToChk.Visible)) then  break;
        aqUtils.Delay(2000,Indicator.Text);
     end;   
      
     //check to see if the property is visivle on screen
     {if  objToChk.Exists then
     begin
        if not objToChk.VisibleOnScreen then
          Log.Warning('The object exists but is not visible on screen');
     end;}
              
     for i := VarArrayHighBound(ObjPropNameArray, 1) downto 0 do
    begin
      propName :=  #13#10+propName+' Property Name ' + TidyString(i+1)  +':  '+ TidyString(ObjPropNameArray[i])+'   '+#13#10;
      propVal :=  #13#10+propVal+' Property Value ' + TidyString(i+1) + ':  ' +TidyString(ObjPropValuesArray[i])+'   '+#13#10;
    end;
    warningTxt := 'Unable to find the propety with Property Details' + #13#10
                            + 'Object Property Names : ' + #13#10 
                            + propName + #13#10 + 
                            + 'Object Property Values : ' + #13#10
                            +propVal + #13#10
                            +' Total Delay Used : ' + TidyString(WaitTime);             
    except
      Log.Error('Exception in CheckPropertyExists routiene,click on addtional Information tab for details... ',exceptionmessage);
    end;
  finally
     if not objToChk.Exists  then
     begin
        if IsLogError then
        begin
            Log.Error('Failed to find the Property,click on addtional Information tab for details... ' ,warningTxt,300,nil,Sys.Desktop.Picture());           
        end;    
         result := false;
     end
     else
     begin      
        result := true;    
    end;      
    Indicator.PopText();
  end;  
end;
Contributor

Re: Wait for Element until its exists

Kinda using something like this in many of my scripts (jscript), which works like a charm and you're able to give a maximum waiting time.

 

 

function WaitForObject(Object, MaxWait)
{ 
  for (var i=0;i<MaxWait;i++)
  {
    if (Object.Exists)
    {
      if (Object.VisibleOnScreen && Object.Enabled)
      {
        Log.Message("Object found & enabled on screen!");
return Object; } } }
Log.Error("Object not found in max number of iterations!"); return false; }

 

Contributor

Re: Wait for Element until its exists

How do you guys handle errors that go to the Log?

I would love to see my test green, but with checking while an element is visible or not visible I am getting this red error signs there, while overall test passes.

Contributor

Re: Wait for Element until its exists

Never try to execute actions on objects that may not exist yet.

 

so no

 

x = <function/command to find the object>

x.click

 

but

 

x = <function/command to find the object>

if (<check if x exists returns true>)

{ x.click }

else

{  Log.Error("Couldnt click x because the object was not found") }

 

Could be that the various TestComplete built-in checks like CheckProperty returns errors when they fail, but I try to refrain from using them unless they don't fill my log with green checks or red errors.

 

Community Hero

Re: Wait for Element until its exists

What @marinb said...  Unless you can pretty much guarentee the object will be there, don't attempt to do anything until it is.

If you're using NameMapping, there's a built-in auto-time out (defaults to 10 seconds) so you might be able to get away with standard functionality.  But if you're performing some action and then checking to see if some other result happened, it's always a good idea to use WaitNNN methods or "FindChild" methods to look for the object and then check the result of that method to determine if it was successful.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.


I’ll be talking about “Hidden Treasures – TestComplete Script Extensions” at #SBConnect in October! Who’s joining me? Click here for tickets
Extensions available
Highlighted
Contributor

Re: Wait for Element until its exists

function waitWhile(condition, msg, timeout)
dim t
t = 0
do While eval(condition) and t <= timeout
delaytext = t & ” of ” & timeout & ” seconds passed waiting for ” & msg
delay 1000, delaytext
t = t + 1
loop
if t <= timeout then
waitWhile = true
else
waitWhile = false
log.event “Timeout expired waiting for ” & msg
end if
end function

An example call to this would look like:

call waitWhile(“aliases.pageObj.find(“”name””, “”elementname””, 4, true).exists”, “element to appear”, 30)

 

Regards

Valla

https://vallatestcomplete.wordpress.com/

Watch a Video Interview
Top Kudoed Authors
Are You In?

Meet the Community Leaders!

SmartBear Connect is an excellent opportunity for training, in-person support, and networking.

GET YOUR TICKET WITH $100 OFF