【问题标题】:UI Automation: How to trigger a tree item's double click event?UI 自动化:如何触发树项的双击事件?
【发布时间】:2018-04-19 22:31:28
【问题描述】:

我喜欢使用 Microsoft UI 自动化测试一个应用程序,但我被困在触发树项目的双击事件中。

Dim parent As AutomationElement
Dim child As AutomationElement

parent = <Code to retrieve parent element>

'expand the parent item
DirectCast(parent.GetCurrentPattern(ExpandCollapsePattern.Pattern), ExpandCollapsePattern).Expand()

'retrieve the child
child = parent.FindFirst(TreeScope.Descendants, New PropertyCondition(AutomationElement.NameProperty, <Name of the child element>))

这个child 对象是有问题的树项,但它只提供ExpandCollapsePatternSelectionItemPattern,它们都对触发双击事件没有帮助。

我试图展开这个项目,以便以这种方式触发双击事件,但我只收到一个错误,告诉我无法展开。

那么,我错过了什么?

非常感谢您。

【问题讨论】:

    标签: .net ui-automation


    【解决方案1】:

    我通过这个问题找到的免费 Microsoft.TestAPI 库设法做到了这一点。

    Given an Automation Element how do i simulate a single left click on it

                using Microsoft.Test.Input;
    
                var p = myTreeNode.GetClickablePoint();
                Mouse.MoveTo(new Point((int)p.X, (int)p.Y));
                Mouse.DoubleClick(MouseButton.Left);
    

    可能有更好的方法将 Windows.Point 转换为 Drawing.Point,但以上方法对我有用。

    【讨论】:

      猜你喜欢
      • 2018-03-31
      • 2012-09-28
      • 1970-01-01
      • 1970-01-01
      • 2012-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多