cancel
Showing results for 
Search instead for 
Did you mean: 

FindChild method is not working in iterations

SOLVED
Highlighted
Occasional Contributor

FindChild method is not working in iterations

     function openRoadCommonFunctions_sideOfCL(sideOfCL)
    {
    try
         {
     
     var hostForm = Aliases.OpenRoadsDesigner.HostForm;
     var listItemsObj = Aliases.OpenRoadsDesigner.DropDownFormEx.StandardValuesListBox;

           var propNames = new Array ("WinFormsControlName");  
           var propValues = new Array ("Misc::Side Of Centerline"); 
         depth = 0;
         counter = 1;
         do
         {
           depth++;
           counter++;
           var sideOfCLTxtBx = hostForm.FindChild(propNames, propValues, 100, true); 
           if(counter > 100)
          {
            break;
          }  
         }
         while(!sideOfCLTxtBx.Exists);    
           

     var propNames = new Array ("ClrClassName");  
     var propValues = new Array ("EditorButton");
         depth = 0;
         counter = 1;
         do
         {
           depth++;
           counter++;
           var sideOfCLListBox = sideOfCLTxtBx.FindChild(propNames, propValues, 100, true);
           if(counter > 100)
          {
            break;
          }  
         }
         while(!sideOfCLListBox.Exists);   
      
       if(sideOfCLListBox.Exists){
          while(!listItemsObj.Exists){
          sideOfCLListBox.ClickButton();
          if(listItemsObj.Exists){
            break;
          }
          }
          Delay(3000, "Selecting Side Of Centerline...");
          methodCount = listItemsObj.wItemCount;
          methodNames = listItemsObj.wItemList;
          Log.Message("Count of Side Of Centerlines " + methodCount +" <::> "+ "Side Of Centerline Types:: " + methodNames);
          listItemsObj.ClickItem(sideOfCL);
       }
       else
       Log.Error("Side Of CL Box does not exist");
   
   }
    catch(exception)
            {
            
            Log.Error("Exception in Side Of CL function", exception.description);
            }
        finally
            {
            Log.PopLogFolder();
            }
    }

I am trying to use the above code in order to select the two values (Left, Right) displayed in the "Lane Creation Method" dropdown. The code works when I select the first option (Left), and it does not click on the dropdown for the second time. It gives me the exception saying  "'Exists' is null or not an object". Is there any other method that can make the clicks on the dropdown without any errors? 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: FindChild method is not working in iterations

Hi,

 

Well, you did not mention language/technology your tested application is based on and if it uses some non-standard controls or the way how they are filled with data, the code might have sence...

Nevertheless, I would recommend to replace search loops with the call to .FindChildEx() or .WaitAliasChild() whatever is more appropriate.

The potential problem with search loops that are based on the objects referred to via Aliases is that for performance reasons TestComplete caches such objects and may not always update their state. This means that if for some reason aliased object was not found when it was referenced and used for the first time, the reference to the empty object might be cached and used within the search loop. Even if the sought for object will appear later while the code is within the loop.

.FindChildEx() should handle the above problem.

Also you may consider to use the .RefreshMappingInfo() method. At least I would strongly recommend to read its description to get a better understanding about the things I mentioned above.

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================

View solution in original post

5 REPLIES 5
Community Hero

Re: FindChild method is not working in iterations

Hi,

 

The code seems to be unnecessary obscured and complex... Maybe because of some reason which is not clear to me.

First: it might help if you let us know what code line errors out with exception and how do you call the function.

Second: what is the real need for all those loops with .FindChild() and .Click() calls inside?

Considering that this is a desktop application, all controls usually exist and are populated with data when the form is opened (or, after some spinner disappears). Even if this is not a case, consider to use the .FindChildEx() method where you may specify the timeout to use for the sought for control to appear.

 

Can you provide a plain language description of what your function is expected to do?

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Occasional Contributor

Re: FindChild method is not working in iterations

Hi,

 

I have to use the loops because sometimes the child is not found in a first go. First, I try to find the text box object textbox.jpg  then the dropdown. Second, I need to click on the dropdown once it's found.

Third,  I need to select the two options (Left/Right) displayed in the list (please see the attached image). 

 

So, the parameter I pass to the function will be Left/Right depending on the need. 

 e.g. openRoadCommonFunctions_sideOfCL("Left"). The function should click on the list box and select the parameter I passed. Sometimes, it does not click on the list box and moves to the else block and throws the error "Aliases.OpenRoadsDesigner.DropDownFormEx.StandardValuesListBox" not found. 

 

I want to select Left/Right option as required. I have also attached a video that shows the steps I do manually.

 

Thanks,

Harshad

Community Hero

Re: FindChild method is not working in iterations

Hi,

 

Well, you did not mention language/technology your tested application is based on and if it uses some non-standard controls or the way how they are filled with data, the code might have sence...

Nevertheless, I would recommend to replace search loops with the call to .FindChildEx() or .WaitAliasChild() whatever is more appropriate.

The potential problem with search loops that are based on the objects referred to via Aliases is that for performance reasons TestComplete caches such objects and may not always update their state. This means that if for some reason aliased object was not found when it was referenced and used for the first time, the reference to the empty object might be cached and used within the search loop. Even if the sought for object will appear later while the code is within the loop.

.FindChildEx() should handle the above problem.

Also you may consider to use the .RefreshMappingInfo() method. At least I would strongly recommend to read its description to get a better understanding about the things I mentioned above.

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================

View solution in original post

Occasional Contributor

Re: FindChild method is not working in iterations

I have tried the FindChildEx() method. It's now working fine for now. 

 

I think RefreshNameMappingInfo() will not be useful as I am not mapping any objects?

 

Thanks,

 

Community Hero

Re: FindChild method is not working in iterations

Hi,

 

> I think RefreshNameMappingInfo() will not be useful as I am not mapping any objects?

It depends on your (current) code.

Have you read mentioned help article (https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/refres...) ?

The code you posted initially was based on aliased objects use (var hostForm = Aliases.[...]; var listItemsObj = Aliases.[...]; ) and .RefreshNameMappingInfo() usually helps if the referenced aliased object is recreated between test code uses it (like it was highly probable for the loop-based version of code).

If your current version of code works as expected, do initial wait for the sought for object(s) via .WaitXXX() method and the object is not recreated within the function, then indeed the call to .RefreshNameMappingInfo() may be not necessary waste of performance.

 

 

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================