Problems with assigning AutomationIds to elements of TreeListView

Grids for WPF Forum

Posted 6 years ago by Bjoern
Version: 17.2.0665
Avatar

Hi,

we are automating our user interface for testing purposes. At the moment we're trying to automatically use our tree control so that we can expand, collapse and invoke (click) its elements.

For that, we need to assign dynamic AutomationId's to our tree items.

The tree is Actipro control based and we're kind of stuck trying to assign these AutomationIds to our tree elements.
The tree itself consist of a TreeListView and it contains an ItemAdapter with the items we want to access in our UI.

<grids:TreeListView x:Name="ListOfTreeItems" RootItem="{Binding RootTreeItem}" [...]

        <grids:TreeListView.ItemAdapter>
            <local:TreeListAdapter x:Name="ItemAdapter"
              ChildrenBinding="{Binding VisibleItems, Mode=OneTime}"             
            />
        </grids:TreeListView.ItemAdapter>

</grids:TreeListView>

 

Is it somehow possible to assign a dynamically generated AutomationId to each individual item in the tree?

Is it generally possible to access the Actipro TreeListView and its Items via UI Automation as an automation element of type TreeControlType?

 

Thanks in advance for any advice!

Comments (3)

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

I first wanted to make a note that in our latest 2018.1 build, we added some UIA peers so that tree list view item peers are directly under the tree list view peer.

While we do support that in the latest build, the UIA peers aren't going to represent the tree structure.  The reason is that items in the control are actually a virtualized flat list with the hierarchy structure maintained behind the scenes.  This keeps the control able to render very fast in a virtualized way.  Due to the virtualization, there will likely only be UIA peers available for the item containers (TreeListViewItem controls) that are currently visible or nearly visible.

There is no automation ID set on the item peers by default.  But you could override the TreeListView.PrepareContainerForItemOverride method and assign an automation ID there.  That might do the trick.


Actipro Software Support

Posted 6 years ago by Bjoern
Avatar

Hello,

your suggestion worked! I created a custom class that overrides the method, calls the base and then sets the AutomationId:

public class TreeListViewOverride : TreeListView
  {
    protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
    {
      base.PrepareContainerForItemOverride(element, item);      
      AutomationProperties.SetAutomationId(element, "customAutomationId");
    } 
  }

Afterwards I used this class in the XAML file instead of the TreeListView.

Is there a way to invoke the expand events on these list items or at least get the expand button? Currently the buttons all got the same AutomationId and can't be found by UI Automation.

Answer - Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

There isn't right now but we will update the UIA peers for items to support the ExpandCollapse pattern for the next build.  


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.