Forum Discussion

Mk1's avatar
Mk1
Occasional Contributor
8 years ago

Hi SmartBear Team,How do i convert a string from property file to an Object? eval is not helping.

'undefined' is null or not an object

this is the value i'm reading from my property file 

 

genericAuthButton=Sys.Browser("iexplore").Page(Project.Variables.pPage).Object("app").PowerCardV3_1("app").HDividedBox("hdividedbox1").CustomTitleWindow("home").P7_autho_period(0).Form(0).Canvas("IDENTIFICATION");

 

below happens in my script

 

var genButPath = context.get("genericAuthButton");

var localBtnPath = eval(genButPath);

var periodCode = localBtnPath;
periodCode.TextInput("period_codeTI").Keys(context.get("PeriodCode"));

  • You can still test your scenario with the below code

     

    function test()
    {
    doStuff(context.get("genericAuthButton"));
    }

    function doStuff(genButPath)//Pass your hasp map string value { var localBtnPath = eval(genButPath);//here your genButPath shouold be your Object FullName if(localBtnPath.Exists) { localBtnPath.TextInput("period_codeTI").Keys(context.get("PeriodCode")); } else { Log.Error("Object not exists for the Fullname" + genButPath); } }

     

  • shankar_r's avatar
    shankar_r
    Community Hero

    Hi,

     

    How you are reading from property file?

    What value you seeing in the genButPath variable?

    Can you post on which line you are getting this error?

     

    I just tried some sample function:

    function Test1()
    {
          var stringVal = Sys.Process("mintty").Window("mintty", "MINGW64*", 1)
          Sys.HighlightObject(eval(stringVal));
    }

     

    • Mk1's avatar
      Mk1
      Occasional Contributor

      Hi Shankar,

       

      I'm using hash map to read my property file, see attached screen. Its returning the right value but of Type String.

      The Value needs to be an object of type object just like "dropDownLocal"

      • shankar_r's avatar
        shankar_r
        Community Hero

        Hi,

         

        Try the below function and share what you got

         

        function doStuff(genButPath)//Pass your hasp map string value
        {
        
              var localBtnPath = eval(genButPath);//here your genButPath shouold be your Object FullName
        
              if(localBtnPath.Exists)
              {
                    localBtnPath.TextInput("period_codeTI").Keys(context.get("PeriodCode"));
              }
              else
              {
                    Log.Error("Object not exists for the Fullname" + genButPath);
              } 
        } 

         

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Eric,

     

    From my understanding the genButPath variable should contain this string:

    Sys.Browser("iexplore").Page(Project.Variables.pPage).Object("app").PowerCardV3_1("app").HDividedBox("hdividedbox1").CustomTitleWindow("home").P7_autho_period(0).Form(0).Canvas("IDENTIFICATION");

     

     

    There is no "genericAuthButton=" at the beginning of the string as it's specified in your case.

     

    Please check this.

     

    • Mk1's avatar
      Mk1
      Occasional Contributor

      Hi Tanya,

       

      The following is generic to all the buttons, so every time i want to click a button i will call the "genericAuthButton" and assign it to a local value

       

      Sys.Browser("iexplore").Page(Project.Variables.pPage).Object("app").PowerCardV3_1("app").HDividedBox("hdividedbox1").CustomTitleWindow("home").P7_autho_period(0).Form(0).Canvas("IDENTIFICATION");