1

我正在使用 Windows 7(64 位)上的 MS UIAutomation。我想知道是否可以使 UIAutomation 元素持续存在,如果可以的话,可以从什么出发点去做。

我唯一想到的是元素的 RuntimeID,但问题是某些元素可能没有 id。

我想要实现的一个简单场景是,我通过使用 找到屏幕上控件的 UIAutomation 元素AutomationElement.FromPoint(),现在我想保留它,以便下次我可以通过将其“加载”回UIAutomation Element.

4

1 回答 1

5

No, you cannot persist the UIAutomation element from the automation client. You will need to store sufficient information about the element (the AutomationID and context are the best, if available) to find it again the next time.

The element is a reference to the object in (probably) some other process, and it can only live so long as that other process lets it. Elements are likely to go away when their windows close, the app closes, etc. Elements such as menus and flyouts are likely to be very short lived, and may no longer exist by the time the client receives a notification.

于 2014-10-14T05:06:19.310 回答