Go through all elements of a treeview

Ask general questions here.
Rika L.
Posts: 18
Joined: Thu Nov 19, 2020 10:03 am

Go through all elements of a treeview

Post by Rika L. » Wed Dec 02, 2020 12:16 am

Hello guys,
Just like the pictures below:
I have a treeview window. My goal is to go through all items in this treeview, left mouse click each tree item and then use same approaches to deal with them. So a 'foreach-loop' is the ideal method.
what I really want is (c#):
         foreach (string itemPath in pathsOfAllItemsInTheTreeview)
         { 
                 LeftMouseClick (itemPath); 
                 Approch (){ ... };
         } 
Path here is RanoreXPath.
But my problem is: the items / tree structure of the treeview are always changed! I hope I can get the paths of all these tree items during the testrun!
Just like:
 List <string > pathsOfAllItemsInTheTreeview = GetPahtsWithTreeviewPath(treeViewPath);

Can I do that with Ranorex?

Thank you very much: )
Lg Rika
Attachments
123.PNG
123.PNG (10.22 KiB) Viewed 366 times

Rika L.
Posts: 18
Joined: Thu Nov 19, 2020 10:03 am

Re: Go through all elements of a treeview

Post by Rika L. » Sat Dec 26, 2020 11:40 am

I answer my question, I hope I can help other green birds like me :D

1. Just use 'find<T>(...)' function to find all treeitems under the outline. Example:
            MyTestRepository repo = MyTestRepository.Instance;
            IList<Ranorex.TreeItem> treeItems = repo.Form1.Outline.Find<Ranorex.TreeItem>(".//TreeItem");
2. Get the tree:
Tree tree = repo.Form1.Self.FindSingle("/?/?/tree[@controlname='treeView1']/tree[@accessiblerole='Outline']");
and the use the tree.items to get subnodes of the tree.

Best regards
Rika