Page 1 of 1

Dump all attributes of an object

Posted: Tue Nov 24, 2015 5:48 pm
by jackrabbit
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");
       	   	}
        }

Re: Dump all attributes of an object

Posted: Thu Nov 26, 2015 1:58 pm
by Support Team
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

Re: Dump all attributes of an object

Posted: Thu Nov 26, 2015 6:35 pm
by jackrabbit
I did not realsed there was another method to get the attribute value,

Thanks!

Re: Dump all attributes of an object

Posted: Tue Jul 26, 2016 3:15 pm
by stapes
Brilliant. I was looking for just such a tool. Thanks.