1 Replies - 477 Views - Last Post: 27 September 2012 - 10:20 AM Rate Topic: -----

#1 brb9412  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 01-January 09

UI Walk

Posted 27 September 2012 - 09:26 AM

I am trying to walk a given UI and retrieve the string of the name of each element (textbox, etc). I have the code below, but it prints out a bunch of lines with " ----> " -- that leads me to believe it's walking the UI correctly, but nothing else prints. Any ideas?

using System;
using System.Windows.Automation;
using System.Windows.Forms;
using UIAutomationClientsideProviders;
using System.Threading;

namespace autoTest
{
	public class WalkEnabledElements
	{
		public WalkEnabledElements (AutomationElement rootElement, TreeNode treeNode)
		{										
			Condition condition1 = new PropertyCondition(AutomationElement.IsControlElementProperty, true);
			Condition condition2 = new PropertyCondition(AutomationElement.IsEnabledProperty, true);
			TreeWalker walker = new TreeWalker(new AndCondition(condition1, condition2));
			AutomationElement elementNode = walker.GetFirstChild(rootElement);

			while (elementNode != null)
			{
				System.Console.WriteLine("-----> ", elementNode.ToString());

				TreeNode childTreeNode = treeNode.Nodes.Add(elementNode.Current.ControlType.LocalizedControlType);
				new WalkEnabledElements(elementNode, childTreeNode);
				elementNode = walker.GetNextSibling(elementNode);

			}

		}
	}
}





Is This A Good Question/Topic? 0
  • +

Replies To: UI Walk

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3574
  • View blog
  • Posts: 11,115
  • Joined: 05-May 12

Re: UI Walk

Posted 27 September 2012 - 10:20 AM

If you want the name, you'll have to crack open the Current property. ToString() doesn't cut it.

http://msdn.microsof...nt.current.aspx
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1