| || |
Using Find to Get An Object
I'm currently working through determining whether TestComplete will work for the web application for which I would like to implement automated testing. This app is built with vb.net and makes use of master pages to display certain content on every page, including a menu for the application. I would like to build out methods to access the menu items generically rather than from each page. I have been able to implement the NativeWebObject.Find method for some of the objects that are displayed on all pages (including the top level menu items), however, I have run into a problem with the actual menu items. These menu items are built out using the standard .net menu object. When these items render on the page, they are built out as list items within list items. Because of this, when I attempt to do a find on a sub-menu item, it finds the parent because whatever text I am attempting to find also exists in the properties of the parent list item. For example, here is some of the code that is rendered for one of our dynamically built .net menus:
<li class="AspNet-Menu-WithChildren" id="menu-root-list-4">
<span class="AspNet-Menu-NonLink">Tools<img src="../Images/arrow-down-white.gif" alt="Tools" /></span>
<a href="../Library/Manager.aspx" class="AspNet-Menu-Link">Library Manager</a>
<a href="../UserGroup/Manager.aspx" class="AspNet-Menu-Link">User Group Manager</a>
<a href="Manager.aspx" class="AspNet-Menu-Link">User Manager</a>
This renders a Tools menu as the top list item and it has three sub menu items - Library Manager, User Group Manager and User Manager. When I attempt to do a find for the User Manager Menu Item so that I can call it's click event after calling the Tools menu click event, it finds the Tools menu item again because the object contains all of the text that is included in each of it's child list items (both the textContent of 'User Manager' and the innerHTML as well). I can't figure out a property of the child list item that will let me find it rather than its parent.
I hope I am explaining this properly. Can anyone assist me in finding a way to access these menu items? It would be a maintenance headache to have to have different methods to access every menu item on every page in the application. Not to mention the fact that the menu items can change depending on a users permissions, so indexes are no help here...
Any ideas/suggestions are greatly appreciated!
Re: Using Find to Get An Object
First of all, please note that you need to refresh the object tree after the popup menu is generated. This will make TestComplete find items of the new menu and add them to the object tree. You can do this by calling the Refresh method of the Page object.
As for the menu items you mention, I recommend that you search for them by the innerText property, not using wildcards. For example:
Set w1 = Page.document.all
Set item = w1.NativeWebObject.Find("innerText", "User Group Manager", "A")
If item.Exists Then
Log.Error "The User Group Manager menu item is not found"