Page 1 of 1

Trouble Extracting Attribute value of Dynamic Capability

Posted: Fri Feb 10, 2017 1:31 am
by nkarora
Hi all,
I am not expert in Ranorex. Just like to know how I can extract the attribute value of Dynamic capability into a variable.
I can validate value using validate method but I can't store the value in a variable.

Can you please suggest

example of my code:

Validate.Attribute(Repo.Sitetrak.JobDetailsForm.Jobs.LaneIdInfo,"disabled","False");

Re: Trouble Extracting Attribute value of Dynamic Capability

Posted: Fri Feb 10, 2017 8:37 am
by odklizec
Hi,

You can use Get Value action to store an attribute value to variable. Translated to code, it looks like this:

Code: Select all

var variableName= Repo.Sitetrak.JobDetailsForm.Jobs.LaneId.Element.GetAttributeValue("AttributeName");
...or this for 'String' attributes:

Code: Select all

string variableName= Repo.Sitetrak.JobDetailsForm.Jobs.LaneId.Element.GetAttributeValueText("AttributeName");
If using Info element, you need to use something like this:

Code: Select all

string variableName= Repo.Sitetrak.JobDetailsForm.Jobs.LaneIdInfo.FindAdapter<ProperAdapterType>().Element.GetAttributeValueText("AttributeName");
BTW, if you are not yet familiar with the individual Ranorex actions, you should definitely stick with the Ranorex Recordings. There is really no advantage of using Ranorex purely in code if you don't know basics ;) And I'm pretty sure that using Recordings (if used properly) can greatly speed up your development process. And you can easily convert each recorded action (or even group of actions) into user code. Eventually, you can copy the code from RecordingName.cs file. This way you can easily learn the code behind each recorded action ;)

Re: Trouble Extracting Attribute value of Dynamic Capability

Posted: Sun Feb 12, 2017 10:40 pm
by nkarora
Hi,
I actually tried below coding mechanism before asking this question. I am getting error for the below option and thought that this option is not valid for this type of property.

Attaching screen for code and the error I am getting :
ERROR: The type arguments for method 'Ranorex.Adapter.GetAttributeValue<T>(string)' cannot be inferred from the usage. Try specifying the type arguments explicitly. (CS0411)
- I used all type of tags available as well but I am not able to get the value.

2. '.GetAttributeValueText' option is not available for the element.
3. Also I don't have option to select 'FindAdapter'. Do I need to load any plug-in or specify any namespace or modify any solution setting?


Thanks
Nav

Re: Trouble Extracting Attribute value of Dynamic Capability

Posted: Mon Feb 13, 2017 5:32 am
by nkarora
I am not sure that this is right solution or not but found the way to store the value in variable.

Here is code.
string Elementpath= Repo.Sitetrak.JobDetailsForm.Jobs.LaneIdInfo.AbsolutePath.ToString();
Element elementforvalue= Ranorex.Core.Element.FromPath(Elementpath);

string storevariable= elementforvalue.GetAttributeValueText("disabled");

Please suggest.

Re: Trouble Extracting Attribute value of Dynamic Capability

Posted: Mon Feb 13, 2017 7:12 am
by odklizec
Hi,

Please upload a Ranorex snapshot (not screenshot) of the problematic element. You are most probably using something wrong or a wrong element? Please upload the snapshot and we will see. Anyway, is there a reason why you need to use code for this instead of Recording action? Have you ever tried Get Value action in recording? This way you can eliminate wrong usage of code ;)

BTW, you don't have Find method available because you are using "laneid" instead of "laneidinfo" in your code!