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?
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.