Enumerate all elements & controls

Class library usage, coding and language questions.
joejeff
Posts: 3
Joined: Wed May 04, 2016 5:03 pm

Enumerate all elements & controls

Post by joejeff » Wed May 04, 2016 5:50 pm

Hi,

I would like to enumerate all elements & controls on the host:

Code: Select all

List<Element> all = (List<Element>)Host.Local.Find(new RxPath("/form"));
			
			foreach(Element e in all)
			{
				Form f = new Form(e);
				
				if(f.Active)
				{
					Console.WriteLine(f.Title);
					
					foreach(Unknown u in f.Children)
					{
						
					}

				}
			}
How do I detect children? I want to have a similar representation as Spy is showing.

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

Re: Enumerate all elements & controls

Post by odklizec » Fri May 06, 2016 10:04 am

Hi,

Could you please post a Ranorex snapshot (not screenshot!) of the form in question? It would help us to understand your GUI and allow us to provide a more accurate answer.
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

joejeff
Posts: 3
Joined: Wed May 04, 2016 5:03 pm

Re: Enumerate all elements & controls

Post by joejeff » Fri May 06, 2016 10:16 am

Thank you for your answer. I am looking to do this generically to cover all guis (very similar to Spy). Therefore I do not have a single Ranorex snapshot.

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

Re: Enumerate all elements & controls

Post by odklizec » Fri May 06, 2016 12:21 pm

Hi,

If there is not disabled creation of complete ancestor subtree (in Ranorex settings), Ranorex should save a complete GUI tree, not just the one element you started from.

Anyway, I don't understand why do you want to recreate the GUI tree similar to the one in Spy? I think you just trying to reinvent the wheel ;)

If you want to create a reference GUI tree (for comparing with actual GUI state), I would suggest to create a Ranorex snapshot from code and then use this snapshot as a reference or whatever do you want to do with it. In my opinion, it's way better option than to create your own (custom) GUI tree. Ranorex folks already put a lot of time and effort into creating and optimizing Spy tree, so why not to use it instead of creating a custom solution? Ranorex snapshot is just a GUI tree stored in file.

Check for example this sample, which compares a snapshot with actual web table...
http://www.ranorex.com/support/user-gui ... html#c8203

And here is a method I'm using for saving Ranorex snapshots from code (to create or re-create reference snapshots whenever needed):

Code: Select all

		public void SaveSnasphot(Ranorex.Adapter repoElementToSave, string filename_ReferenceTableSnapshot)
		{
			ElementSnapshot elementSnapshot = ElementSnapshot.Capture(repoElementToSave, true);
		var xmlDoc = elementSnapshot.SerializeXmlDoc();
			FileStream fs = new FileStream(@filename_ReferenceTableSnapshot, FileMode.Create, FileAccess.ReadWrite, FileShare.Read);
			xmlDoc.Write(fs);
			Ranorex.Report.Log (ReportLevel.Info, "New reference table saved.");
		}
You see, it's pointless to recreate something that already exists ;)
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