如何从AutomationElement获取实际的UWP控制元素
以下接口返回AutomationElement
parent.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, automationId));我想断言元素的特定属性和相应值。对于ex。图像控件的url。
如何才能获得实际的控件或它的属性?谢谢
发布于 2019-06-04 19:01:23
如果是WPF应用程序,则需要执行以下步骤才能获得实际控制。

发布于 2019-05-24 16:58:51
首先,您必须确保automationId值与您的图像控件匹配。然后,您必须将FindFirst的结果转换为ImageControl。
var imageControl = parent.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, automationId)) as ImageControl;我还建议使用更高级的UI自动化库,如TestStack.White或FlaUI,它们具有这些扩展方法,您可以根据控件类型和实际Id传递条件。
例如: Flaui有这样的接口:
var submitBtn= parent.FindFirstDescendant(cf => cf.ByName("SubmitBtn").And(cf.ByControlType(ControlType.Button)))?.AsButton();https://stackoverflow.com/questions/56284413
复制相似问题