Forum Discussion

shiva_ranabhat's avatar
shiva_ranabhat
Contributor
10 years ago

Counter not working in do-while loop?

Hi,

 

I wanted to delay a webpage until certain element appears OR certain wait-time has passed.

Here is my code:

 

var counter= 0;
do{
aqUtils.Delay(100);
counter+= 100;
obj = pagereport.NativeWebObject.Find("contentText", "Resource Activity Volumes");
}
while (! obj.Exists || counter<=5000);

 

During playback, even after 'Resource Activity Volumes' text appears, it keeps playing back... in a loop :mansad:

 

Best Regards,

Shiva

  • Ryan_Moran's avatar
    Ryan_Moran
    10 years ago

    Try using WaitAliasChild like so:

     

    Aliases.browser.pageRedOwlReports.formAspnetform.panelReportPanel.WaitAliasChild(cellResourceActivityVolumes,5000).Exists

     

  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor
    var counter= 0;
    do{
    aqUtils.Delay(100);
    counter+= 100;
    obj = pagereport.NativeWebObject.Find("contentText", "Resource Activity Volumes");
    }
    while (! obj.Exists && counter<=5000);

     Assuming you mean to use counter as a timeout of sorts....I think you mean to have && not || counter < = 5000.

  • chrisb's avatar
    chrisb
    Regular Contributor

    I think your problem is this line

     

    obj = pagereport.NativeWebObject.Find("contentText", "Resource Activity Volumes");

     

     

    Try this:

     

    var obj = Sys.Browser("yourbrowsername").Page("yourpageurl").NativeWebObject.Find("contentText","Resource Activity Volumes");

     

    You need to tell Test Complete the path to the object you are looking for, so in the example above we start with your local machine and drill down to the page, then search the page for the element your require.

     

    Take a look at the documentation below to undertsand the browser and page objects:

     

    page objects: support.smartbear.com/viewarticle/55305

    browser objects: support.smartbear.com/viewarticle/55711

     

     

     

     

  • Thats it Ryan. The loop issue is solved but the counter doesn't seem to work because, TestComplete "delays" until 'Activity Volume' is displayed on the screen. Meaning [ Counter<= 5000] condition is true all the time. 

    failcounter.jpg

     

    Hi Chrisb, the result is same even if I give full path to the object. Variable pagereport is actually giving the path name. I highly believe that the counter isn't working. 

     

    Best Regards,

    Shiva

    • Ryan_Moran's avatar
      Ryan_Moran
      Valued Contributor

      Well no...the counter will not delay for exactly 5 seconds (5000 milliseconds) as you have specified because there will be an additional delay with the .Find method. What exactly are you trying to accomplish? Do you want this to fail within 5 seconds if the object is not found? If that is your goal I would suggest using WaitNNN method on the object with a 5000 MS timeout specified.

      If you provide the objects FullName I can provide an example.

       

      More information here.

      • shiva_ranabhat's avatar
        shiva_ranabhat
        Contributor

        Thanks Ryan, thats it.

         

        when I put 100ms delay, TC was actually taking longer than 5s which made it look like counter didn't work. 

        If i change the delay time to 1000 ms and counter<= 2500, its working fine. 

         

        I would love to use WaitNNN method (never knew). Here is the objects full name:

         

        "Aliases.browser.pageRedOwlReports.formAspnetform.panelReportPanel.cellResourceActivityVolumes"

         

        or

        Sys.Browser("iexplore").Page("http://redowl-web1/RedOwl/RSReport/RSReport.aspx").Form("aspnetForm").Panel("content").Panel("panels").Panel("rightPanel").Panel("rightContent").Panel("mainColumnTop").Panel("reportPanel").Panel("report_panel").Panel(0).Panel(0).Panel("reportViewerDiv").Panel("ContentPlaceholderRight_ContentPlaceHolderMain_UpdatePanel1").Panel("ContentPlaceholderRight_ContentPlaceHolderMain_reportViewer").Table("ContentPlaceholderRight_ContentPlaceHolderMain_reportViewer_fixedTable").Cell(4, 2).Panel(0).Panel(0).Panel("P0639d4ddab204b1b8e8079d362352638_2_oReportDiv").Table(0).Cell(0, 0).Panel("P0639d4ddab204b1b8e8079d362352638_2_gr").Panel("P0639d4ddab204b1b8e8079d362352638_2_gr").Panel("P0639d4ddab204b1b8e8079d362352638_2_11xB_gr").Table(0).Cell(1, 1)

         

        Its a dynamically generated website so name mapping is really helpful.

         

        Regards,

        Shiva 

         

         

         

         

    • chrisb's avatar
      chrisb
      Regular Contributor
      yep, Ryan got the root of the issue. Did a face palm when I realized I missed that! Good luck.