Forum Discussion

underqualified's avatar
underqualified
Occasional Contributor
6 years ago

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.w...
  • AlexKaras's avatar
    6 years ago

    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();

      // ...

    }