相关疑难解决方法(0)

AutomationElement使用Inspect.exe显示,但在使用UIAutomationCore.dll或System.Windows.Automation时显示不亮.

TL; DR:我做错了什么导致工作区窗格显示在Inspect Objects中但未显示在我的自定义代码中?


我正在尝试为第三方程序编写一些UI自动化.我正在使用Windows SDK附带的Inspect.exe,我已经尝试过System.Windows.Automation和直接COM调用(使用UIA Verify的包装器库).

Process[] processes = Process.GetProcessesByName("Redacted Client");
if (processes.Length == 0) throw new Exception("Could not find \"Redacted Client\" process");

PropertyCondition parentFileCond = new PropertyCondition(AutomationElement.ProcessIdProperty, processes[0].Id);
PropertyCondition workspaceCond = new PropertyCondition(AutomationElement.NameProperty, "Workspace", PropertyConditionFlags.IgnoreCase);
PropertyCondition documentCond = new PropertyCondition(AutomationElement.NameProperty, "Untitled3", PropertyConditionFlags.IgnoreCase);

var parentElement = AutomationElement.RootElement.FindFirst(TreeScope.Children, parentFileCond);
var workspaceElement = parentElement.FindFirst(TreeScope.Children, workspaceCond); //Also does not work with TreeScope.Descendants
var documentElement = workspaceElement.FindFirst(TreeScope.Children, documentCond);
Run Code Online (Sandbox Code Playgroud)

当我尝试上面的代码时,parentElement确实有对主程序窗口的正确引用,但是workspaceElement为null. …

.net c# automation ui-automation

27
推荐指数
1
解决办法
2万
查看次数

单击其他程序工具栏中的按钮

我正在尝试在我没有源的遗留应用程序上自动化一些东西。所以我基本上是在尝试使用 Windows API 来单击我需要的按钮。

有一个msvb_lib_toolbar看起来像这样的工具栏:

工具栏

我可以通过使用以下代码来处理它(我认为):

IntPtr window = FindWindow("ThunderRT6FormDC", "redacted");
IntPtr bar = FindWindowEx(window, IntPtr.Zero,"msvb_lib_toolbar",null);
Run Code Online (Sandbox Code Playgroud)

查看文档,似乎我应该能够使用SendMessageTB_PRESSBUTTON单击这些按钮的消息:

[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);
Run Code Online (Sandbox Code Playgroud)

但是,我不确定如何设置wParamlParam单击栏上的所需按钮。该文档似乎也没有多大帮助。

您能否提一些建议?


根据评论,我也尝试过UIAutomation. 我可以使用以下代码找到工具栏:

AutomationElement mainWindow = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Migration Expert"));
AutomationElement toolbar = mainWindow.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.ClassNameProperty, "msvb_lib_toolbar"));
Run Code Online (Sandbox Code Playgroud)

但是从这里开始,我不确定该怎么做,因为 Spy++ 没有显示此对象的其他子项:

间谍++

看着这个Current属性,AutomationElement我看不到任何东西跳出来,但BoundingRectangle似乎表明我找到了正确的元素。

调试器

使用inspector.exe也不会指示工具栏上的任何子项。

检查员

c# winapi user32 ui-automation

6
推荐指数
1
解决办法
476
查看次数

为什么 Inspect.exe 经常挂起并且显示 AutomationId 不一致?

我正在尝试使用 MS UI Automation 来测试 WPF 应用程序,并使用 Windows SDK 中包含的检查对象工具 (inspect.exe) 来查找某些元素的 AutomationId 属性。

Inspect 对我来说表现得很奇怪:

  • 如果我关闭所有应用程序并启动 WPF 应用程序和检查,检查将能够查看各种 UI 元素的 AutomationId 属性。没有 AutomationId 的元素仅显示两个引号,表示空字符串 ("")。

  • 在 WPF 应用程序中执行一些操作后,inspect.exe 挂起,我必须终止它并重新启动它。尽管机器的 CPU 和 RAM 利用率约为 50% 或更低,但我尝试等待几分钟(有几次可能接近 20 或 30 分钟),但无济于事。

  • 重新启动后,inspect.exe 无法再找到任何 UI 元素的 AutomationId,即使是那些之前有的元素。更重要的是,当鼠标悬停在 WPF 应用程序上时,该属性完全消失——它根本不再列出,甚至没有空字符串值。
  • 如果我将鼠标移动到另一个屏幕(具体来说,使用无边框鼠标移动到另一台计算机),AutomationId 属性会重新出现,且值为“FormDot”
  • 如果我在 WPF 应用程序仍在运行时仅重新启动检查额外几次,则检查的行为仍与第一次重新启动后相同。
  • 如果我在检查仍在运行时仅重新启动 WPF 应用程序,则检查的行为仍与首次重新启动后相同。
  • 如果我关闭检查和 WPF 应用程序,然后启动检查,然后启动 WPF 应用程序,一切都会正常工作一段时间,并且检查会在 WPF 应用程序中的几个元素上找到 AutomationId...直到检查挂起为止再次。

我尝试按照/sf/answers/548360991/中的建议正常运行检查并以管理员身份运行检查,并且无论哪种方式,它的行为都是相同的。

如果有的话,我做错了什么?我是否太不耐烦了,我是否需要等待很长时间而不是假设检查已挂起?为什么检查关于 AutomationId 的行为会有所不同?

wpf ui-automation inspect microsoft-ui-automation

5
推荐指数
1
解决办法
3404
查看次数