Forum Discussion

blatec's avatar
blatec
Occasional Contributor
8 years ago
Solved

How can i find the Alias-Path to a Webelement

Hi

 

I want to search for a web element by his id or name and return the Alias - Path.

Can i realize this with a script?

 

something like:

 

 var xxx = Aliases.frameMainwindow.Find("NativeWebObject.id", "*Gender", 500);

 and get the Alias Path of xxx 

 

 

 

regards

 

Horst

 

 

 

  • In the general case, you can have object names like Aliases.browser.page.Panel(0).Link("myLink")where only a few parent objects have aliases. So the idea is to go up the chain of parent objects until you find the one with a non-empty MappedName, then combine it with the Name's of other objects. Something like this:

     

     

    function Test()
    {
      Log.Message(GetAlias(Sys));
      Log.Message(GetAlias(Sys.Process("explorer")));
      Log.Message(GetAlias(Aliases.notepad.Window("#32770", "Font").Window("Button", "OK")));
    }
    
    function GetAlias(obj)
    {
      if (obj.MappedName != "") return obj.MappedName;  // object has its own alias
      if (obj.Parent == null)   return obj.Name; // Sys and Mobile
    
      // Append the object name to the parent object's alias
      var alias = GetAlias(obj.Parent) + "." + obj.Name;
      return alias;
    }

     

2 Replies

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    In the general case, you can have object names like Aliases.browser.page.Panel(0).Link("myLink")where only a few parent objects have aliases. So the idea is to go up the chain of parent objects until you find the one with a non-empty MappedName, then combine it with the Name's of other objects. Something like this:

     

     

    function Test()
    {
      Log.Message(GetAlias(Sys));
      Log.Message(GetAlias(Sys.Process("explorer")));
      Log.Message(GetAlias(Aliases.notepad.Window("#32770", "Font").Window("Button", "OK")));
    }
    
    function GetAlias(obj)
    {
      if (obj.MappedName != "") return obj.MappedName;  // object has its own alias
      if (obj.Parent == null)   return obj.Name; // Sys and Mobile
    
      // Append the object name to the parent object's alias
      var alias = GetAlias(obj.Parent) + "." + obj.Name;
      return alias;
    }

     

  • baxatob's avatar
    baxatob
    Community Hero

    Hi

     

    You can't get the Alias of the element before you have mapped it.

    However you can obtain a FullName property, which in fact is a full path of your element.

     

    xxx.FullName