How to better identify objects in a web page.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How to better identify objects in a web page.
Hi
I use the following properties to identify an object (drop-down-listbox).
ObjectType: Panel contentText: Select...
However, there are two objects with these properties and I am unable to find a third unique property to use. Any ideas?
This is the method I use to locate the object:
/** * Function Name:selectListbox * Description: find the object * @param {string} browserAUT * @param {string} lstobjType (example "Panel") * @param {string} lststr. - the text of the particular object (example "Select...") * @param {string} sublstobjType (example "Panel") * @param {string} sulststr. - the text of the particular object (example "Male") * @param (boolean) */ function selectListbox(browserAUT, lstobjType, lststr, sublstobjType, sulststr) { spUtils.beginlog("selectListbox"); var page = Sys.Browser(browserAUT).Page("*"); var lstbox_PropArray, lstbox_ValuesArray, lstbox; lstbox_PropArray = new Array("ObjectType", "contentText"); lstbox_ValuesArray = new Array(lstobjType, lststr); lstbox = page.FindChild(lstbox_PropArray, lstbox_ValuesArray, 2000); if (lstbox.Exists) { Sys.HighlightObject(lstbox); Log.Message(lstbox.FullName); lstbox.Click(); } else Log.Error("The object was not found."); /** * SUB LIST ITEM */ var sublstbox_PropArray, sublstbox_ValuesArray, sublstbox; sublstbox_PropArray = new Array("ObjectType", "contentText"); sublstbox_ValuesArray = new Array(sublstobjType, sulststr); sublstbox = page.FindChild(sublstbox_PropArray, sublstbox_ValuesArray, 2000); if (sublstbox.Exists) { Log.Message(sublstbox.FullName); sublstbox.Click(); } else Log.Error("The object was not found."); spUtils.endlog(); }
Obviously the label name is unique, but I can't use it to open the list box.
Attached file has a copy of the Object Spy properties.
NOTE: The page is created by react and id's are dynamic so I can't use any react id confidently.
Thank you
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What about ObjectIdentifier or idStr? Usually, if the page is constructed well, these will have unique values for each control.
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Not at this case....
Refer to the attached Object Spy snapshots
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
OK, I see what's going on...
You're calling "FindChild" from the page level... That's going to search the entire tree at the page level for the object... and it will grab whatever it finds as the first item. Since all the Select boxes are identified pretty much the same way, it's the tree hierarchy that is the identifying factor keeping them separate. You need to start your search closer within the hierarchy to the object you're wanting to select. I'm assuming that the "Gender" panel can be found by caption or label or innerText or something. Once you find that panel, then you can do a "FindChild" to find the select box you need.
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@tristaanogre wrote:
You're calling "FindChild" from the page level... That's going to search the entire tree at the page level for the object... and it will grab whatever it finds as the first item.
Yup.
That's also a horribly inefficient way of finding objects.
As @tristaanogre, you need to make it more targeted and efficient.
I use a name map for the high level pages, containers, panels etc. Then small "helper" functions to find individual controls within them. That's my preference. And it works well enough for me.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you @Colin_McCrae. I agree that it is somewhat inefficient but I am trying to avoid name mapping all together.
@tristaanogre has a good point to narrow the search while pointing to the label object. What is the best way (without name mapping) to find the label (Gender)?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Well, without knowing exactly how the "Gender" panel shows up in the object browser, hard to give you specifics. My assumption is that "Gender" is in the innerText of a "div" panel. So, I'd do a FindChild to look for the container with that innerText (perhaps other properties as well to make sure you get the right one). Then, from that container, do your FindChild to get your "Select" control. It's two searches rather than one.
And see, that's where NameMapping give you the benefit. The two searches are going to take time, reducing performance of your overall test. NameMapping will give you improved performance if done correctly because the "search" that NameMapping does is in the compiled code of TestComplete and not in the interpreted code of your script. If you are adamently against NameMapping, then two FindChild calls it is.
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
