royd
8 years agoRegular Contributor
Problem with "FindAllChildren"
I am trying to find all menu items. I am getting error "Unable to find the object aspnetForm.", see the screcapture bellow. I am new to Jscript, Probably making a simple mistake, help is much appreciated.
Besides the issue I am having, I would also like to know is, once found how do I click on one of the menu, say "Admission Form". An exaple would be very helpful. Here is the code:
var page = Sys.Browser("*").Page("https://<testapplication>.com/MainMenu.aspx*"); var mainMenu = page.aspnetForm.panelMainMenu; //see the capture bellow // Search for all menu links var menuChild = mainMenu.FindAllChildren("contentText", 50, true).toArray(); menuChild = (new VBArray(menuChild)).toArray(); // Log the search results if (menuChild.length > 0) { for (i = 0; i < menuChild.length; i++) Log.Message(menuChild[i].contentText); Log.Message("Total number of menu items found are: " + menuChild.length); } else Log.Warning("No menu items found.");
Thanks in advance.
You dont't need to convert the below to array.
mainMenu.FindAllChildren("ObjectType","link", 50, true);
When you use FindAllChildren by default it will return as a Array.
FYI.
- FindAllChildren Method (Common for All Test Objects)Declaration
TestObj.FindAllChildren(PropNames, PropValues, Depth, Refresh)
TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section PropNames [in] Required Variant PropValues [in] Required Variant Depth [in] Optional Integer Default value: 1 Refresh [in] Optional Boolean Default value: True Result An array of the tested objects.
Once you got the list of menus available from the Pane to menuChild object.
You can script something like below.
var menuChild = mainMenu.FindAllChildren("ObjectType","link", 50, true); // Log the search results if (menuChild.length > 0) { for (i = 0; i < menuChild.length; i++) //For clicking
menuChild[i].Click();
//You can do your stuffs } else Log.Warning("No menu items found.");- FindAllChildren Method (Common for All Test Objects)