我想在測試期間使用Windows AutomationElement
s來模擬Userinput。 我的particulat用例是manupilating列表框選擇和我在網上找到的,我將需要一個AutomationElement爲我的列表框來操縱它。獲取WPF用戶控件的自動化元素
假設我有這樣一個窗口:
<Window x:Class="CryptoAdmin_Test.Helper.FreshWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CryptoAdmin_Test.Helper">
<StackPanel>
<UserControl x:FieldModifier="public" x:Name="FindMe" />
</StackPanel>
</Window>
由於我必須到用戶控件的一個參考,我應該能夠找到它,而無需啓動從桌面(AutomationElement.RootElement
)我的搜索。
什麼是最快的方式獲得AutomationElement
我的window.FindMe
UserControl
?
使用AutomationElement.RootElement.FindFirst(...);
將開始與桌面,我沒有看到一種通用的方式,這將使此搜索快速沒有任何可能的誤報。
是的,我不得不放棄試圖找到任何東西,而不從根開始。 – Johannes