Dump all attributes of an object

Ask general questions here.
jackrabbit
Posts: 47
Joined: Wed Mar 18, 2015 10:06 pm

Dump all attributes of an object

Post by jackrabbit » Tue Nov 24, 2015 5:48 pm

I have a menu / sub-menu in my programs, and I need to examine all the available attributes of the sub-menu. The problem is that this sub-menu disapears as soon as I try to click on the EDIT button in the repository, making it impossible to browse its attributes.

So I wrote a small function to display all the available atributes of any Ranorex Path passed as a parameter. This way, I can make my sub-menu appear, then call my function to get a list of the attributes. It almost works, it shows all attributes names, but I am anable to display the attributes values. What is wrong with my code?

Code: Select all

        public void DumpProperties(string PropertyName, string PropertyPath)
        {
        	Report.Info(PropertyName + " (" + PropertyPath + ")");
       	   	Ranorex.Unknown obj = null;
        	if (Host.Local.TryFindSingle(PropertyPath, 10000,  out obj)) {
        		foreach (Ranorex.Core.AttributeDescriptor item in obj.Element.Attributes) {
       	   			Report.Info(String.Format("- {0} = {1}", item.DisplayName, item.ToString()));
        		}
       	   	} else {
       	   		Report.Info(" - Object not found");
       	   	}
        }

User avatar
Support Team
Site Admin
Site Admin
Posts: 11710
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Dump all attributes of an object

Post by Support Team » Thu Nov 26, 2015 1:58 pm

Hi jackrabbit ,

The problem is that you don't ask for the value of the attribute in your code.
Please try to use the the following code lines in your loop in order to get the values.
var attrValue = obj.Element.GetAttributeValue(item.ToString());
Report.Info(String.Format("- {0} = {1}", item.DisplayName, attrValue));
I hope that helps.

Regards,
Bernhard
.
Image

jackrabbit
Posts: 47
Joined: Wed Mar 18, 2015 10:06 pm

Re: Dump all attributes of an object

Post by jackrabbit » Thu Nov 26, 2015 6:35 pm

I did not realsed there was another method to get the attribute value,

Thanks!

stapes
Posts: 206
Joined: Wed Sep 16, 2015 10:55 am

Re: Dump all attributes of an object

Post by stapes » Tue Jul 26, 2016 3:15 pm

Brilliant. I was looking for just such a tool. Thanks.