cancel
Showing results for 
Search instead for 
Did you mean: 

Click Object based on name

SOLVED
Highlighted
Occasional Contributor

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

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

  // ...

}

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] 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. Posts made by [Community Heroes]
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.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

4 REPLIES 4
Highlighted
Community Hero

The container Panel will have a property in TestComplete Object Browser called "ChildCount".  You can find out how many panels are below the clickMenu from that property and create a For loop that will go through all the panels underneath and click on each one of them.

 

Cheers

Lino

Highlighted
Occasional Contributor

I'm not sure how I'd go on to do that, though - is there any guide on that specific case in the Testcomplete documentation?

Highlighted
Community Hero

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

  // ...

}

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] 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. Posts made by [Community Heroes]
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.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

Highlighted
Community Manager

Thank you so much AlexKaras and LinoTadros! 

 

Hi @underqualified , were you able to implement the eval() or evaluate() function Alex is suggesting that you use? Was it a success? 


Sonya Mihaljova
Community and Education Specialist

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!


Challenge Status

Get properties of a web page element

See replies!

Compare images using the Region Checkpoint

See replies!

Compare HTML table with Excel file and correct data in Excel file

Participate!

How to execute remote test and obtain results via Test Runner REST API

Participate!
Top Kudoed Authors