Page 1 of 1

SelectPath and Path Seperator in TreeView

Posted: Mon Feb 18, 2008 10:41 am
by Klaes
Hello!

The Ranorex.TreeView class uses a simple slash "/" to seperate the nodes within the SelectPath() method. In general this works fine!

But how can I use SelectPath() even if a TreeView contain nodes with slashes e.g. "n/a"? Is there a way to "escape" the slash? Well, how can I tell SelectPath() that the following slash is NO path seperator but a node text?

Thanks in advance!
Stephan

Posted: Mon Feb 18, 2008 1:44 pm
by Support Team
I found a workaround in an old thread:

http://www.ranorex.com/forum/locating-a ... w-t95.html

I tried it with the sample VS2005Application and it worked for me.
(I changed the node "SecondNode - FirstChild" to "Second/Node - FirstChild")

Can you please try the following code:

Code: Select all

TreeView treeView = form.FindTreeView("treeView1");
LocatePath(form, treeView, @"SecondNode\Second/Node - FirstChild");

static void LocatePath(Form form, TreeView treeView, string path)
{
    // Break down the path 
    string[] folderList = path.Split(@"\".ToCharArray());

    // Locate the path 
    bool ret = Locate(treeView, folderList);
}

static bool Locate(TreeView treeView, string[] folderList)
{
    // Get the root tree view element in the control 
    // The tree view itself has the role Role.Outline 
    Element treeElement = treeView.Element.FindChild(Role.Outline);

    // Get the count of the children 
    int childCount = treeElement.GetChildCount;
    // Traverse the tree 
    int level = 0;
    for (int i = 0; i < childCount && level < folderList.Length; i++)
    {
        Element node = treeElement.GetChild(i);
        if (node == null)
            break;

        if (node.Name == folderList[level])
        {
            node.Select(Selection.TakeFocus | Selection.TakeSelection);
            Mouse.MoveToElement(node);
            treeView.SendKeys("{RIGHT}");
            if (level == folderList.Length - 1)
                return true;
            else
                level++;
        }
    }
    return false;
}
Jenö
Ranorex Support Team