Forum Discussion

Jerryth's avatar
Jerryth
Occasional Contributor
8 years ago

Using variables in expressions for drop down menus

I am trying to make selections from a drop down menu bar.
(running against different translations so I can't use plain English text)

Instead of saying a cryptic (which works correctly)
    w.MainMenu.Click('[2|4]');

 

I would like to say 

    w.MainMenu.Click('[mnuSettings|mnuConfigs]');

 

where mnuSettings has been defined = 2 and mnuConfigs = 4

 

I started with a simple version:
w.MainMenu.Click('[ProjectSuite.Variables.VariableByName(mnuSetup)]');

which gives me 
"The control item '[ProjectSuite.Variables.VariableByName(mnuSetup)]' not found."

 

Is what I want to do possible?

Thanks

  • Basically, what you need to keep in mind is that the contents of your variables are the strings you are replacing.  So, you need to make sure that the "Click" method, when the whole expression evaluates, looks like the string you want it to be. 

    In shankar_r's code, you have your first variable followed by an operator that concatenates that variable with the string '|'.  That is then concatenated with your second variable.

     

    I'm not sure where the brackets are coming from that you're trying to use.  Again, those are parts of the initial string.  If that's the case, modify shankar_r's code like so:

    w.MainMenu.Click('[' + ProjectSuite.Variables.mnuSetup + "|" + ProjectSuite.Variables.mnuConfigDisplayAndUnits + ']');
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Sure... just remove the single quotes. The single quotes mean you're passing a literal string into the "Click" method.  So, since you want to click on the value contained within mnuSetup, simply pass the variable to the Click method.  Additionally, ProjectSuite.Variables allows you to just call the variable name rather than having to call "VariableByName".  So, your command should be able to just be as follows.

     

    w.MainMenu.Click(ProjectSuite.Variables.mnuSetup);

     

    • Jerryth's avatar
      Jerryth
      Occasional Contributor

      Thanks for the fast reply!

      That was part of my problem but not all of it.

       

      Going with single level specifier works

      w.MainMenu.Click(ProjectSuite.Variables.mnuSetup);

       

      I tried to specify 2 levels (To match this functionality  w.MainMenu.Click('[2|4]'); )

      w.MainMenu.Click(ProjectSuite.Variables.mnuSetup|ProjectSuite.Variables.mnuConfigDisplayAndUnits);

      error 110: SYNTAX ERROR while lexing character "|"

       

      So I tried adding the brackets [  ]

      w.MainMenu.Click([ProjectSuite.Variables.mnuSetup|ProjectSuite.Variables.mnuConfigDisplayAndUnits]);

      same result

       

      I tried a comma

      w.MainMenu.Click(ProjectSuite.Variables.mnuSetup,ProjectSuite,Variables.mnuConfigDisplayAndUnits);

      "Wrong number of parameters or invalid property assignment. "

       

      I tried square brackets + quotes
      w.MainMenu.Click('[ProjectSuite.Variables.mnuSetup|ProjectSuite.Variables.mnuConfigDisplayAndUnits]');

      "The control item '[ProjectSuite.Variables.mnuSetup]' not found."

       

      Do you see what I am messing up?

      • shankar_r's avatar
        shankar_r
        Community Hero

        I modified your code like below which will work,

         

        VBScript

         

        w.MainMenu.Click(ProjectSuite.Variables.mnuSetup & "|" & ProjectSuite.Variables.mnuConfigDisplayAndUnits);

         

        JavaScript

         

        w.MainMenu.Click(ProjectSuite.Variables.mnuSetup + "|" + ProjectSuite.Variables.mnuConfigDisplayAndUnits);

         

        let me know your results.