How do I find child controls under a specific container UIItem?

May 13, 2010 at 3:08 AM

Assume a UI where there are multiple tab pages, each page has a zoom slider. How do I get the zoom slider of a particular named tab page ?


I've tinkered a bit and what worked was

  • get the window by name
  • get the tab page by tab header
  • then fall back to UI automation - tabPage.AutomationElement.FindAll or FindFirst with the right constraint/condition

Is there a more "white" way to get hold of child controls within a parent container/control ?

Also in some cases, the child controls are not accessible - UISpy shows them only in the raw / unfiltered view and not in the control view. e.g. A DataGridCell shows a certain value within a TextBlock. The UISpy control view ends at a custom control for DataGridCell ; the raw view shows more children under it. Does White have a native way to get to the raw children ? I coded up an extension method that finds raw children but was wondering if I reinvented the wheel coz I couldn't find it.

Finally falling back to UI Automation meant that I lost out on the really nice White UIItem wrappers. I hacked it by doing something like

new Button(buttonAutomationElementSearchResult, NullActionListener)

It works but is it the right approach to cast from AutomationElement to specific UIItem?

So that's 3 questions in all... In summary - very impressed with this framework. Great work!!

-- Gishu


May 18, 2010 at 5:14 AM

get hold of child controls within a parent container/control

What is the control type of the zoom slider? You are right upto step 2. After this you can select the tab. Then you can use the window to Get the UIItem you want.

Does White have a native way to get to the raw children

cast from AutomationElement to specific UIItem?

Ideally you shouldn't have to do this but when you do then instead of passing NullActionListener please pass the owning window. This is required for Wait Handling.

May 25, 2010 at 10:50 AM

Thanks vivek. Got you on Bullet#2 and #3.

On #1, I'm still not sure. A WPF tab control blows off everything other than the active tab contents.. so I guess that's why using the Window.Get<Button> would work (as long as you select the tab beforehand).

So I'll rephrase the question, given a specific parent UIItem derivation, how do I only search for elements under it. (i.e. subtree with parent as root).

e.g. if I have a list view using data templates, I'd have similar controls for each list view item. If I want to find a specific control in the template expansion of ListViewItem#4, how do I go about it ? I can get the ListViewItem for Item#4, but then how do I search for a specific descendant ?

Jun 3, 2010 at 8:34 AM

Hopefully I get your question right.

The behaviour of Tab is slightly different as the items which are inside tab are not children of tabpage, as you would have noticed.

Regarding your other question, ListViewItem. If ListViewItem doesn't expose items inside it directly then you can use extension methods as explained in WPF Items section here.