Page 1 of 1

get the value of a select tag in user code

Posted: Tue Jun 17, 2014 9:43 pm
by Rajaniboyapati
I am trying to use a new user code using If..else condition, I have a drop down list box where based on the item selected in the drop down I have to enter values in the subsequent fields.

like if selected value is A then enter the values in the subsequent fields as 1,2,3,4
else if selected value is B then enter the values in the subsequent fields as 6,7,8,9

now my question is how to incorporate this in the if condition.I am trying to figure out what method I should use to get the select value from drop down.


var repo = ScorecardRepository.Instance;
var productSets1 = repo.RSASecurIDLogIn.ProductSets1;

if repo.RSASecurIDLogIn.ProductSets1. ?

Re: get the value of a select tag in user code

Posted: Wed Jun 18, 2014 1:33 pm
by krstcs
How are you picking the select tag? Are you just picking it based on an index (first, second, etc.)?

Or, are you passing in the value you want selected? If so, you can just use that value in your if.

If it is the first one, you would actually want to get the option tag's value after the selection is made. If the option tag's value is also an index, you will need to get a list of the option tags and their values and then match them up. A lot of this depends on how your developers coded the system.


It would be helpful for us if you could post a snapshot of the select tag in question. See this link for information on creating a snapshot: http://www.ranorex.com/support/user-gui ... files.html

Re: get the value of a select tag in user code

Posted: Wed Jun 18, 2014 2:33 pm
by Rajaniboyapati
I have a recorded code that is clicking on the list box with mouse click event and then added a key sequence action and typed the value which is parameterized by the way, after that value is selected I want to add this user code where if selected value is abc then enter values for subsequent values.

Please bear with me as I am new to the tool as well as C# coding, I did search the forum for similar issue and most of them that I fould was to loop on the select tag based on index and then select the required value, my question is what is the method used to get the selected value.

Re: get the value of a select tag in user code

Posted: Wed Jun 18, 2014 3:33 pm
by krstcs
As I said, I would recommend that you use the variable value (the value you are putting in the keysequence action) in the if. You could validate that the select tag is set to that value (or that the innertext of the select tag is equal) before you do anything else.

For example, the action table would look like this:

Mouse -> Click -> Left -> Center -> <Your Select Tag object>
Keyboard -> Key sequence -> $typedValue -> <Your Select Tag object>
UserCode -> MyMethod -> $typedValue

In user code it would look like:

Code: Select all

public void MyMethod(string typedValue)
{
    if (typedValue.Equals("ABC"))
    {
        //do stuff here...
    } else if (typedValue.Equals("DEF")) {
        //do stuff here...
    } else if (typedValue.Equals("GHI")) {
        //do stuff here...
    } else if (typedValue.Equals("JKL")) {
        //do stuff here...
    }
}
The problem with hard-coding like this is that you will then have to change it when the application changes.

Re: get the value of a select tag in user code

Posted: Wed Jun 18, 2014 4:40 pm
by Rajaniboyapati
will try it, Thank you.