微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

只有使用AutomationElement.FromPoint方法

如何解决只有使用AutomationElement.FromPoint方法

我有点想获得ToolStrip按钮。我无法通过Name属性获取它,只能通过其坐标来获取

用户界面如下:UI scshot

工具栏由按钮和进度条组成。所有的ToolStrip按钮都会导致以下所述的相同问题。

执行此操作时,将找到并返回AutomationElement:

var aElemByCoordinates = AutomationElement.FromPoint(new System.Windows.Point(462,877));

但是当我这样做时,会返回null:

TreeScope treescope =  TreeScope.Element | TreeScope.Children | TreeScope.Descendants;
var aElemByName =  parentAutomationElement.FindFirst(treescope,new PropertyCondition(AutomationElement.NameProperty,aElemByCoordinates.Current.Name)); // How is that possible...?

除了ToolStrip中包含的按钮之外,我还可以在窗口中包含其他ToolStrip按钮。使用Inspect可以看到控件。

关于坐标收集的AutomationElement还有另外一件奇怪的事情。当我找到它的父级,然后查看父级子级时,AutomationElement(坐标收集的工具条按钮元素)不在此处。 简而言之,父母没有孩子,而孩子以父母为父母。

我对自动化元素的行为感到非常困惑。 有时它的行为就像它存在,而另一次则不存在

最近我和我的同事发现将进度条放在按钮后面可以解决问题

有人知道什么可能导致这种奇怪的行为吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。