torus's avatar
torus
Contributor
10 months ago
Status:
New Idea

Ability to get the get/extract the XPath or Css from the name mapping objects

I would like to have one location where I specify the xpath my html elements. Most of the time, this data is stored in the NameMapping. A lot of the time you can use aliases in scripts. However, there are some times ... like for the 'waitelement' which you have to use the xpath or css. I would really like to be able to get the xpath or css from the nameMapping. This would make things a lot safer and less error prone. I use keyword tests as much as I can, but there are times when scripting is beneficial. 

 

var myAlias = Aliases.MyWebApp.AdminButton;

var selectorArray = myAlias.GetSelectors();

 

the selectorArray would be an array of objects that looks like this:

selectorArray = [{'css', '#myAdminButton'}, {'xpath', '//div/button[contains(@class, 'adminbutton')]'}, {'xpath', //div//button}]

2 Comments

  • For the above, it would also be critical to be able to get the xpath or css-selectors regardless of whether or not the element currently exists on the page 

     

  • There is a way to extract the xpath from name mapped object. Unfortunately, if I'm not mistaken, it works only if the mapped element exists in UI. The ability to get the xpath also from not an existing element is something I'm really missing too. 

    Here is the solution I'm currently using (returns the first xpath):

    //get xpath from mapped element
    function GetXpathFromAlias(mappedElement) 
    {
      let str = mappedElement.Name;
      let match = str.match(/\"(.*)\"/);
      if (match) 
      {
        let substring = match ? match[1] : '';
        return substring;
      }
      {
        Log.Error("XPath not found." + str);
      }
    }