【问题标题】:Are there any dependencies for UI Automation?UI 自动化是否有任何依赖项?
【发布时间】:2017-07-18 23:18:46
【问题描述】:
我有一个 Windows 应用程序,它根据配置从屏幕捕获详细信息。我正在使用 UI 自动化从屏幕上捕获详细信息。在安装了 Visual Studio 的开发人员机器上一切正常。当我在另一个仅安装了 .NET Framework 4.5 的系统上运行相同的应用程序时,它开始出现奇怪的行为,并且无法检测到子元素。
我的问题是为什么它在安装了 Visual Studio 和 .NET Framework 的开发人员机器上运行良好。有什么不同?就先决条件而言,我们还缺少什么吗? UI 自动化的任何依赖项或我们缺少的任何库..?
提前致谢 - 请帮帮我。
【问题讨论】:
标签:
c#
.net
visual-studio-2012
ui-automation
microsoft-ui-automation
【解决方案1】:
它看起来像是 .NET 包装器中围绕原生 UIAutomationCore.dll 的一个已知错误(是的,它的核心不是 .NET)。它已包含在 WinVista+ 中(.NET Framework 甚至在 WinXP 中也添加了它)。
这里是 C# example 如何使用 C# 中的本机 COM API (UIAutomationCore.dll)。复制代码在这里:
using System;
using interop.UIAutomationCore;
namespace PrintDesktopUiaElementNameViaCom
{
class PrintDesktopUiaElementNameViaComProgram
{
static void Main(string[] args)
{
// Instantiate the UIA object:
IUIAutomation _automation = new CUIAutomation();
// Get the root element
IUIAutomationElement rootElement = _automation.GetRootElement();
// Get its name
string rootName = rootElement.CurrentName;
Console.WriteLine(
"The root automation element's name should be 'Desktop'.");
Console.WriteLine("The actual value is: '{0}'", rootName);
}
}
}