【问题标题】:How to enable a button using UIAutomation or White如何使用 UIAutomation 或 White 启用按钮
【发布时间】:2011-03-15 12:36:40
【问题描述】:

我正在尝试自动化安装向导,我需要单击一个未启用的按钮。

我知道这可以使用 Windows 消息来完成,但我想知道 White 或 UIAutomation 是否已经对此提供支持

仅供参考,这不起作用:

var invoke =  (System.Windows.Automation.InvokePattern)setup.button("Next >").AutomationElement.GetCurrentPattern(System.Windows.Automation.InvokePattern.Pattern);  
invoke.Invoke();

也没有

var guiAutomation = new API_GuiAutomation("msiexec");  
var setup = guiAutomation.windows()[0]; 
setup .bringToFront(); 
setup .button("Next >").mouse().click();  // this will work
setup .button("Next >").mouse().click();  // this will not work since the button is not enabled

上面的示例使用了我添加到 O2 Platform 的基于 White 的 API(请参阅此处的 example of automating notepad

【问题讨论】:

    标签: c# ui-automation white-framework


    【解决方案1】:

    我不相信你可以用 UIAutomation 做到这一点:你所要求的是超出 UIAutomation 框架范围的东西。它旨在让您可以像使用鼠标和键盘一样使用代码。它并非设计为操纵 UI 状态的通用方法。

    【讨论】:

    • 嗯,更改 UI 控件(如按钮)的状态是一项非常有用的测试/自动化功能 :)
    【解决方案2】:

    你可以直接调用Win32函数EnableWindow,就像你说的那样发送一个Windows Message。

    我在 UIAutomation 中寻找该功能,但没有找到。

    【讨论】:

      【解决方案3】:

      单击启用的按钮与故障注入技术有关,而不是应用程序的正常执行。 该按钮是在应用程序的剩余生命周期中禁用还是稍后启用?如果是后者,为什么不等待启用呢?通过在 element.Current.IsEnabled 或 Wait-UIAButton cmdlet 上使用 do/while。

      【讨论】:

        【解决方案4】:

        如果您使用白色

        Mouse.Instance.Location = this.ClickablePoint;

        Mouse.LeftDown(); Mouse.Instance.Location = 点; Mouse.LeftUp();

        【讨论】:

        • O2 使用白色进行 Windows 自动化。顺便说一句,您的代码示例将无法工作,因为该按钮未启用
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-05-06
        • 1970-01-01
        • 2019-12-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-10
        相关资源
        最近更新 更多