Ask a Question

Using the find method(s) ...not sure what I am doing wrong

Super Contributor

Using the find method(s) ...not sure what I am doing wrong

My goal is to expose the on screen objects I want exposed in script (and obfuscate the hierarchy in name mapping...). 


I have some code:


/// This script exposes objects frm the LOGIN PAGE for use in tests.
var pageRoot = Aliases.browser.pageMain;
function lblProductTitle()

  var item = pageRoot.Panel("window_header").Panel("header_top").Panel("product_title");
  return item;

This works fine for this simple object which is named. But I am not understanding the FIND method which I would like to use.


Take this example:

function txtUserName()
  var item = pageRoot.Panel("window_content").Panel(0).Panel("frame1").Form(0).Panel(0).Panel(0).Panel(0).Panel(0).Panel(0).Textbox("loginstart_username")
  return item;

I would LIKE to find the object by name but not have to traverse the DOM. 


function txtUserName()
  //var item = pageRoot.Panel("window_content").Panel(0).Panel("frame1").Form(0).Panel(0).Panel(0).Panel(0).Panel(0).Panel(0).Textbox("loginstart_username")
  var item = pageRoot.Find("Name", "loginstart_username", 9999, true);
  return item;

But the item is returning an empty object. Nothing is found. I am clearly not understanding this method... Can anyone explain what I am misunderstanding? THANKS!


Esteemed Contributor

The "Name" property is not what you think it is.  It's actually, if you look at it in the Object Spy the full name of "TextBox('loginstart_username')".  It's not a recommended property to find for.


What you probably want to do, if you're going to use "Find", is to actually pass in arrays of properties and values.  So, in your example, you would want something like


pageRoot.Find(['ObjectType', 'ObjectIdentifier'],['TextBox', 'loginstart_username'], 9999, true)


Now... that all said....  what you're trying to do, as I see it, is remove all those "Panel.Panel.Panel" references...and you say that you're doing so to obfuscate NameMapping... probably aren't using the Aliases right in NameMapping then.

Basically, if I have an object that NameMapping might map like


The Alias, when you first map it MIGHT look like this.


Well, if you edit your Alias, you can drag loginTextBox to be a direct chiild of the page and then "Exclude" all the intermediary stuff.   So, your NameMapping.Sys will still look the same (which is OK... and necessary) but your Alias will look like


Read up on NameMapping at


While Find WILL work....  you end up with an overhead that is unnecessary.  Find, actually, consumes more time and processor time than if you're using the NameMapping repository for object identification.  And, with NameMapping, there's less code to maintain and keep track of.  Check it out.

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

Thanks for the info! I was aware of the alias movement that I could do. I am doing a PoC of both approaches to show the good, the bad and the ugly. I will add performance to the ugly! Thanks again.

Showing results for 
Search instead for 
Did you mean: