Trouble Extracting Attribute value of Dynamic Capability

Ranorex Studio, Spy, Recorder, and Driver.
nkarora
Posts: 12
Joined: Mon Dec 05, 2016 12:54 am

Trouble Extracting Attribute value of Dynamic Capability

Post by nkarora » Fri Feb 10, 2017 1:31 am

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");

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Trouble Extracting Attribute value of Dynamic Capability

Post by odklizec » Fri Feb 10, 2017 8:37 am

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 ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

nkarora
Posts: 12
Joined: Mon Dec 05, 2016 12:54 am

Re: Trouble Extracting Attribute value of Dynamic Capability

Post by nkarora » Sun Feb 12, 2017 10:40 pm

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
You do not have the required permissions to view the files attached to this post.

nkarora
Posts: 12
Joined: Mon Dec 05, 2016 12:54 am

Re: Trouble Extracting Attribute value of Dynamic Capability

Post by nkarora » Mon Feb 13, 2017 5:32 am

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.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Trouble Extracting Attribute value of Dynamic Capability

Post by odklizec » Mon Feb 13, 2017 7:12 am

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!
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration