SelectPath and Path Seperator in TreeView : Automation API

SelectPath and Path Seperator in TreeView

Class library usage, coding and language questions.

SelectPath and Path Seperator in TreeView

Postby Klaes » Mon Feb 18, 2008 11:41 am

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
Klaes
 
Posts: 1
Joined: Mon Jan 21, 2008 2:28 pm

Postby Support Team » Mon Feb 18, 2008 2:44 pm

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
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria


Return to Automation API

Who is online

Users browsing this forum: No registered users and 0 guests

cron