问题描述
我有点想获得ToolStrip按钮。我无法通过Name属性来获取它,只能通过其坐标来获取它。
工具栏由按钮和进度条组成。所有的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 (将#修改为@)