This is a migrated thread and some comments may be shown as answers.

Working with TreeView (selecting elements)

6 Answers 143 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jess
Top achievements
Rank 1
Jess asked on 16 Mar 2012, 04:48 PM
I am new to Test Framework so would appreciate a gentle introduction to working with TreeView control. I find it, do an initial click on it to expand it to it's "first level" of nodes but I then need to select the little "node arrow" next to the item in the TreeView to open up the "second level" of items in the TreeView. It's this "second click" on the little "arrow" icon next to the TreeViewItem in the TreeView control that I have to click... not sure how to do this. Any feedback is appreciated. I don't know if I have to get the *exact* x/y coordinates of that arrow next to the Item and do a User.Click(with x/y coordinates or whatever the API specifies) or if I can just set focus on a TreeViewItem and simulate the Click event on that TreeViewItem itself. Again, kinda lost so any help is appreciated.

By the way I have to write code to do this as I only have the Test Framework free edition available to me. 

Thanks!

Jess

6 Answers, 1 is accepted

Sort by
0
Accepted
Plamen
Telerik team
answered on 21 Mar 2012, 04:22 PM
Hi Jess,

Is this a Silverlight or an HTML TreeView? The following code is for Silverlight TreeView control. It will find a TreeViewItem by its text content and will expand the node by pressing the ToggleButton.
SilverlightApp app = ActiveBrowser.SilverlightApps()[0];
 
TreeView tree = app.Find.ByType<TreeView>();
IList<TreeViewItem> items = tree.Find.AllByType<TreeViewItem>();
 
foreach (TreeViewItem item in items)
{
    //Find an item by its text content and expand the node
    if (item.Text == "TextContent")
    {
        ToggleButton button = item.Find.ByType<ToggleButton>();
        button.User.Click();
    }
}

Let me know if you require further assistance on this.

Greetings,
Plamen
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Jess
Top achievements
Rank 1
answered on 21 Mar 2012, 04:23 PM
Hello,

It's a Silverlight TreeView.

Thanks for your response. I'll give it a shot. 

take care,

J
0
Petr
Top achievements
Rank 1
answered on 03 Jan 2013, 12:02 PM
Hello Plamen,

I also have a problem with my treeview. I checked your solution and it works. However, I`d like to be able to data drive my tests and change textcontent depending on different values. So instead of "TextContent" I`d like to use a variable and data drive it. Could you please advise a solution for this?

Thank you.

Petr
0
Boyan Boev
Telerik team
answered on 09 Jan 2013, 05:27 PM
Hi Petr,

This is a duplicate of support ticket 646366, let's continue the discussion there.

I will update this post with the final solution.

Thank you for your cooperation. 

Regards,
Boyan Boev
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Humberto
Top achievements
Rank 1
answered on 18 Dec 2013, 06:47 PM
A link to the new post or forum would be nice; some of us would like to follow up to glean the new found knowledge.  Please?
0
Boyan Boev
Telerik team
answered on 23 Dec 2013, 09:35 AM
Hi Humberto,

Here is an example against our demo site:

SilverlightApp app = ActiveBrowser.SilverlightApps()[0];
Telerik.WebAii.Controls.Xaml.RadTreeView tree = app.Find.ByType<Telerik.WebAii.Controls.Xaml.RadTreeView>();
IList<RadTreeViewItem> items = tree.Find.AllByType<RadTreeViewItem>();
  
  
  
  
foreach (RadTreeViewItem item1 in items)
   
  if (item1.Text == "Gold")
                        {
ToggleButton button1 = item1.Find.ByType<ToggleButton>();
  
 button1.User.Click();
System.Threading.Thread.Sleep(2000);
   item1.Refresh();
IList<TextBlock> items2 = item1.Find.AllByType<TextBlock>();
                            foreach (var item in items2)
                            {
                                if(item.Text=="Norway")
                                {
                                    item.User.Click();
                                }
                            }
                        }
  
                    }

It clicks on the toggle button "Gold" and then clicks on the "Norway" TextBlock.

Hope that helps.

Regards,
Boyan Boev
Telerik
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Jess
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Jess
Top achievements
Rank 1
Petr
Top achievements
Rank 1
Boyan Boev
Telerik team
Humberto
Top achievements
Rank 1
Share this question
or