Page 1 of 1
Enumerate all elements & controls
Posted: Wed May 04, 2016 5:50 pm
by joejeff
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.
Re: Enumerate all elements & controls
Posted: Fri May 06, 2016 10:04 am
by odklizec
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.
Re: Enumerate all elements & controls
Posted: Fri May 06, 2016 10:16 am
by joejeff
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.
Re: Enumerate all elements & controls
Posted: Fri May 06, 2016 12:21 pm
by odklizec
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