Working with TreeView (selecting elements)

7 posts, 1 answers
  1. Jess
    Jess avatar
    3 posts
    Member since:
    Jan 2012

    Posted 16 Mar 2012 Link to this post

    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
  2. Answer
    Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 21 Mar 2012 Link to this post

    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
  3. Jess
    Jess avatar
    3 posts
    Member since:
    Jan 2012

    Posted 21 Mar 2012 Link to this post

    Hello,

    It's a Silverlight TreeView.

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

    take care,

    J
  4. Petr
    Petr avatar
    17 posts
    Member since:
    Sep 2012

    Posted 03 Jan 2013 Link to this post

    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
  5. Boyan Boev
    Admin
    Boyan Boev avatar
    1040 posts

    Posted 09 Jan 2013 Link to this post

    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
  6. Humberto
    Humberto avatar
    8 posts
    Member since:
    Mar 2012

    Posted 18 Dec 2013 Link to this post

    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?
  7. Boyan Boev
    Admin
    Boyan Boev avatar
    1040 posts

    Posted 23 Dec 2013 Link to this post

    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
Back to Top