[英]Microsoft ui-automation not able to fetch chrome's context menu elements
[英]UI-Automation cmdlet not finding the control
我正在嘗試使用MSFT提供的UI自動化框架來測試WPF應用程序。 編寫了一些powershell腳本,這些腳本調用了為操縱應用程序的可視控件而創建的cmdlet。
我的應用程序中有一個DropDown,其中有一個條目“ DropDownEntry”。 在我的cmdlet中,我嘗試執行以下操作:
AutomationElement getItem = DropDown.FindFirst(TreeScope.Descendants,
new AndCondition(
new PropertyCondition(AutomationElement.ControlTypeProperty,ControlType.ListItem),
new PropertyCondition(AutomationElement.NameProperty, "DropDownEntry",PropertyConditionFlags.IgnoreCase)));
上面給出的代碼片段在執行時返回“ null”,這實際上意味着上面給出的邏輯無法找到我的下拉條目。
有人可以告訴我為什么會這樣嗎? 我檢查了控件的名稱和值。 一切似乎都井井有條。 我不確定為什么會這樣。 任何幫助將非常感激。
謝謝
由於這是您要自動執行的DropDown控件,因此可能只有在DropDown下拉之前,子項才可以通過UIAutomation使用。
您需要從DropDown元素獲取ExpandCollapse模式,然后調用其Expand方法。
我創建了一些擴展方法來幫助掌握模式。 這是一個例子
public static class PatternExtensions
{
public static ExpandCollapsePattern GetExpandCollapsePattern(this AutomationElement element)
{
return element.GetPattern<ExpandCollapsePattern>(ExpandCollapsePattern.Pattern);
}
public static T GetPattern<T>(this AutomationElement element, AutomationPattern pattern) where T : class
{
object patternObject = null;
element.TryGetCurrentPattern(pattern, out patternObject);
return patternObject as T;
}
}
像這樣使用它:
DropDown.GetExpandCollapsePattern().Expand()
然后,您可以執行原始代碼以找到子元素。
如果還沒有,您可能需要使用UISpy檢查應用程序以驗證屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.