Forum Discussion

lodecesa's avatar
lodecesa
Contributor
2 years ago
Solved

Reference to an HTML object having a string with his mapped name

Hi to all, I have the mapped name of an HTML object in a string and I want find its reference with a method like this:

 

var elementReference = Aliases.browser.page.form.byName(mappedName);

 

Thanks to all

  • Hi,

     

    Assuming that you have:

    var aStr = "Aliases.browser.page.form.mappedName";

    Are you looking for this:

    var anObj = eval(aStr);

    ?

     

5 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    Assuming that you have:

    var aStr = "Aliases.browser.page.form.mappedName";

    Are you looking for this:

    var anObj = eval(aStr);

    ?

     

    • lodecesa's avatar
      lodecesa
      Contributor

      AlexKaras wrote:

      Hi,

       

      Assuming that you have:

      var aStr = "Aliases.browser.page.form.mappedName";

      Are you looking for this:

      var anObj = eval(aStr);

      ?

       


      Yes, this solution works as I was suggested by ChatGPT after several attempts. The final form I used is this:

       

      function (elementAlias) {
      
        // The prefix to be added before the alias of the element
        var aliasPrefix = "Aliases.browser.page.form.";
      
        // Retrieve the element through the alias
        var element = eval(aliasPrefix + elementAlias);
      
        // Interact with the element
        element.Click();
      
      }

       

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        as I was suggested by ChatGPT after several attempts.

        Funny πŸ™‚

        Just curious what your request succeeded? (I.e. whether ChatGPT already processed this Community or it was solution from some other forum/for some other language.)