Hello UIAutomation World with WPF
I am currently trying to figure out how the new UIAutmation works. I tried the "Hello World" approach, i.e. the (almost) simplest possible example wich uses UIAutmation to simply click a WPF Button. The Apps UI looks like this:
<Windowx:Class="UIAutomationTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="UIAutomationTest"Height="328"Width="334"MouseDown="Window1_MouseDown"
>
<Button
AutomationProperties.AutomationId="Button"
AutomationProperties.Name="Button"
AutomationProperties.ItemType="Button"
Name="Button"
Width="100"
Height="100"
Click="Button1_Click">Button</Button>
</Window>
Its just a simple window with a button inside wich has some AutomationProperties defined. When the client area of the window is clicked I want the Button's click to be Simulated via UIAutmation. I tried it like this in the Window1_MouseDown:
PropertyCondition findWindow =newPropertyCondition(AutomationElement.NameProperty,this.Title);
AutomationElement window =AutomationElement.RootElement.FindFirst(TreeScope.Descendants, findWindow);
PropertyCondition findButton =newPropertyCondition(AutomationElement.AutomationIdProperty,"Button");
AutomationElement button = window.FindFirst(TreeScope.Descendants, findButton);// this returns null :(
InvokePattern pattern = button.GetCurrentPattern(InvokePattern.Pattern)asInvokePattern;
pattern.Invoke();
No matter how I configure thee PropertyCondition findButton, FindFirst()alwaysreturns null. What am I doing wrong here?
While are at it: Do Ihave toset the AutomationProperties for WPF controls to make them Discoverable via UIAutmation? Or will UIAutomation be able to find WPF controls anyway. For example when I ask UIAutmation to find all AutomationElements that are AutomationType.ControlType ControlType.Button, will it find all System.Windows.Controls.Buttons?
Also: Is it possible to simulate a Mouseclick anywhere on a given UIElement? (and trigger the belonging WPF events) ? If so, is there a simple example?
Here you can download the (currently not working) simple example I am talking about (Visual Studio Project for with .NET 3.0 RC1).
Thank your for your help.

