Getting all child tree items at run time

Best practices, code snippets for common functionality, examples, and guidelines.
rickcuddihey
Posts: 6
Joined: Fri Mar 14, 2014 8:04 pm

Getting all child tree items at run time

Post by rickcuddihey » Thu Jan 17, 2019 7:38 pm

Hi,

I have a parent tree element that can have different child elements at run time. I don't care about the child elements I just want to expand all of them because they also have children. I cannot put all the child elements in the repo because there are many and as I mentioned they can be different so I don't know what they will be in terms of text, etc.

I do have the parent element in the repo because it does not change. How can I get the run time element using the repo item for the parent node?
Once I get this I can easily get the child elements under the parent.

Right now I have this, yes I know it not much but I've been messing around for awhile trying to figure it out and reset :)

public void Set_value_TreeItem(RepoItemInfo treeitemInfo)
{
var toptreeitem = treeitemInfo.FindAdapter<TreeItem>();


Note I am an Automation developer with 12 years experience in Automation and 5 years in software development so I don't need much explanation I just need to know how to access the run time application objects like Test Complete and other tools do instead of using the repository items.

Thank you !!!

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

Re: Getting all child tree items at run time

Post by odklizec » Thu Jan 17, 2019 8:54 pm

Hi,

I think this example code should help you...
https://www.ranorex.com/help/latest/han ... oryelement

Just instead of button, user treeitem element and do whatever you want with individual tree items.
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

rickcuddihey
Posts: 6
Joined: Fri Mar 14, 2014 8:04 pm

Re: Getting all child tree items at run time

Post by rickcuddihey » Fri Jan 18, 2019 9:11 pm

Great. Thank you. That did help. I can expand the three children under the top node. After that I cannot get the children of the next nodes.

This truly is frustrating. I must need to invoke an update on each child after I get the list from CreateAdapter() or something???

Here's where I am. If you any suggestions I would appreciate it.

public void Set_value_EngineTreeItem(RepoItemInfo treeitemInfo)
{
var parent = treeitemInfo.CreateAdapters<Ranorex.TreeItem>();

foreach (Ranorex.TreeItem child in parent)
{
// works and expands the child
child.Expand();

// does nothing, no items
foreach (Ranorex.TreeItem anotherchild in child.Items)
{
anotherchild.Expand();
}

// does not return anything so foreach does nothing
var nextchildern = child.FindChildren<TreeItem>();

foreach (Ranorex.TreeItem anotherchild in nextchildern)
{
anotherchild.Expand();
}
}
}

McTurtle
Posts: 227
Joined: Thu Feb 23, 2017 10:37 am
Location: Benedikt, Slovenia

Re: Getting all child tree items at run time

Post by McTurtle » Mon Jan 21, 2019 12:03 pm

Hi Rick,

I think that we will need a Ranorex Snapshot in order to help you. Please expand all the whole tree manually and then create a Ranorex Snapshot of the root element. Please create a snapshot like this: How to create a Ranorex Snapshot

Regards,
McTurtle