How to retrieve attribute value from Dynamic in listitem

Best practices, code snippets for common functionality, examples, and guidelines.
JillNarra
Posts: 3
Joined: Thu Aug 15, 2019 3:52 pm

How to retrieve attribute value from Dynamic in listitem

Post by JillNarra » Thu Aug 15, 2019 4:16 pm

Hi,

I need your help on how to retrieve the text from "c" attribute from a listItem. I have the following implementation below. However, I am receiving an exception that it object is not set to an instance of an object.
Ranorex spy.JPG
THis is what I want to retrieve from "c" attribute from Dynamic
Ranorex spy.JPG (176.5 KiB) Viewed 132 times
List.JPG
THis is the path of the list I used from repository
List.JPG (46 KiB) Viewed 132 times
implementation.JPG
This is how I implemented it
implementation.JPG (22.56 KiB) Viewed 132 times
Thank you so much for the help.

User avatar
qwertzu
Posts: 273
Joined: Wed Jan 25, 2017 11:08 am

Re: How to retrieve attribute value from Dynamic in listitem

Post by qwertzu » Fri Aug 16, 2019 9:10 am

Hi Jill,

First of all, you will need a different path, that points to all of your list items.
In your case, this would be possible by adding "/listitem" at the end of your path of your "MoveletList" element.
So, the path should end with //[email protected]='na']/listitem
This will be a path to all of the list items.

Afterwards, you need to adapt your code a little bit.

Use the following:

Code: Select all


IList<Ranorex.ListItem> list = repo.Movilizer.ContainerHv.MoveletListInfo.CreateAdapters<Ranorex.ListItem>();

foreach (Ranorex.ListItem item in list) {
        		
        		string moveletCategory = item.Element.GetAttributeValueText("c");
        		...
        		...
        	}

This should work.

regards, qwertzu

JillNarra
Posts: 3
Joined: Thu Aug 15, 2019 3:52 pm

Re: How to retrieve attribute value from Dynamic in listitem

Post by JillNarra » Fri Aug 16, 2019 1:57 pm

Hi qwertzu,

It actually works! Thank you!