简体   繁体   English

wxWidgets和UI自动化

[英]wxWidgets and UI Automation

I have a small application using wxWidgets, running on MS Windows. 我有一个使用wxWidgets的小型应用程序,可在MS Windows上运行。 I'm using UI Automation to do automated testing. 我正在使用UI自动化进行自动化测试。 For the most part, this is going quite well. 在大多数情况下,这进行得很好。 However, I've hit a snag. 但是,我遇到了障碍。

For most widgets, it seems that the UIA "Name" property matches whatever the text on the widget is. 对于大多数小部件,UIA的“名称”属性似乎与小部件上的文本匹配。 (I don't know whether wxWidgets does this or whether UIA does it.) But for image buttons... yeah, no text. (我不知道wxWidgets是否这样做还是UIA是否这样做。)但是对于图像按钮……是的,没有文本。 So what I want to do is add some kind of property to these widgets that makes them uniquely identifiable through UIA, without altering the visual appearance of the GUI. 因此,我想做的就是在这些小部件中添加某种属性,以使其可以通过UIA进行唯一标识,而无需更改GUI的外观。

I had hoped that simply setting the "name" property in the window designer would do this... but sadly no. 我曾希望仅在窗口设计器中设置“ name”属性就可以做到这一点……但可惜没有。 Any ideas how I can fix this? 有什么想法我可以解决这个问题吗?

The name is not used at MS Windows level. 在MS Windows级别不使用该名称。 The only thing which is the ID, so if you use fixed unique IDs (as opposed to specifying wxID_ANY when creating your windows), you should be able to find the window during run-time from them. 唯一的是ID,因此,如果您使用固定的唯一ID(而不是在创建窗口时指定wxID_ANY ),则应该能够在运行时从中找到窗口。

Edit: The ID can be queried from UIA using the AutomationIdProperty , like so: 编辑:可以使用AutomationIdProperty从UIA查询ID,如下所示:

string id = (string)widget.GetCurrentPropertyValue(AutomationElement.AutomationIdProperty);

Usually the string is a decimal number, but not always. 通常,字符串是十进制数字,但并非总是如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM