Click Object based on name
Hey everybody! I'm currently trying to automate a test that clicks on a bunch of panels in repetition.
The panels are all part of the same menu that I've already mapped, let's say "Aliases.browser.website.clickMenu", and the panels are all named "Panel(0)", "Panel(1)", "Panel(2)" and so forth, but I do not know how many panels there actually are. How would a script have to look that clicks all panels under clickMenu, in order of the number in the name?
Thanks in advance!
Hi,
As Lino (LinoTadros) suggested. You should use eval()/evaluate() function whatever is provided by the scripting language of your test project.
Sample untested pseudo-code:
var mainMenu = Aliases.browser.website.clickMenu;
// open menu, so its sub-items are generated
mainMenu.HoverMouse();
var subitemsCount = mainMenu.FindAllChildren('ObjectIdentifier', 'Panel').length;
for (var i = 0; i < subitemsCount; i++)
{
mainMenu.HoverMouse(); // required for the second and up loop iterations to open menu items
var str = 'var submenuItem = ' + mainMenu.AliasedName + '.Panel(' + i + ')'; // should resolve to e.g. "var submenuItem = Aliases.browser.website.clickMenu.Panel(0)"
eval(str); // this will resolve Panel object and assign it to the submenuItem variable
submenuItem.Click();
// ...
}