简体   繁体   English

从弹出菜单中选择一个项目

[英]Selecting an item from pop-up menu

I'm trying to make an application that will test some features of an existing app and I wanted it not to be window-size dependent and not to require focusing the window or etc. 我正在尝试制作一个可以测试现有应用程序某些功能的应用程序,我希望它不依赖于窗口大小,也不需要聚焦于窗口等。

I've already figured out how to get window handles for different controls in the tested app so I can click buttons, enter text to textboxes etc. with Send/Post Message but still got a few unsolved problems. 我已经弄清楚了如何在测试的应用程序中获取不同控件的窗口句柄,因此我可以单击按钮,使用“发送/发布消息”在文本框中输入文本等,但是仍然存在一些未解决的问题。

The first is selecting an item from a pop-up menu that can be triggered by button click (TAdvGlowMenuButton class) or right click somewhere- I can't even see any messages related to it in Spy++ so I have no idea how to do it, is it possible to select an item by name? 首先是从弹出菜单中选择一个项目,该项目可以通过单击按钮(TAdvGlowMenuButton类)或在某处单击鼠标右键来触发-我什至在Spy ++中都看不到与此相关的任何消息,所以我不知道该怎么做,是否可以通过名称选择项目? as I don't have it's id 因为我没有身份证

The second thing is clicking next to something, for example 10 pixels to the right of a button. 第二件事是单击某个事物旁边的事物,例如按钮右侧的10像素。 I have the button handle so I can get it's size and it's parent but I still don't know how to get it's position inside the parent - any ideas?:) 我有按钮句柄,所以我可以得到它的大小和它的父对象,但是我仍然不知道如何获得它在父对象中的位置-有什么想法吗?

And also a quick one but I don't believe it is possible - can I somehow get position of a label in the tested app? 也是一种快速的方法,但我不认为有可能-我能以某种方式在测试的应用程序中获得标签的位置吗? I can't even see it in Spy++ . 我什至在Spy ++中都看不到它。

I hope you can help me to find it out ;) 我希望你能帮助我找出来;)

Edit: I forgot about the most important thing:P , I'd like to achieve it with Send/Post Message if only it is possible. 编辑:我忘了最重要的事情:P,如果可能的话,我想通过发送/发布消息来实现它。

My recommendation would be to abandon the message sending/posting model altogether and instead use UI Automation . 我的建议是完全放弃消息发送/发布模型,而改用UI Automation Automated testing tools is exactly what the UI Automation APIs were designed for, and they are much more capable than SendMessage/PostMessage. 自动化测试工具正是UI自动化API的设计目的,并且比SendMessage / PostMessage更加强大。

Yes, I realize that this is exactly the opposite of the answer you were looking for. 是的,我知道这与您要寻找的答案完全相反。 But you will have no end of trouble getting messages to do what you want. 但是,获取消息来做您想做的事情没有麻烦。 A fair number of them rely on the application having the focus, and it is completely reasonable for your code to make this assumption when you receive eg a WM_KEYDOWN message. 其中相当一部分依赖于具有焦点的应用程序,并且当您收到例如WM_KEYDOWN消息时,代码对此假设是完全合理的。 A testing tool should not flag that as a bug. 测试工具不应将其标记为错误。

I notice you've tagged this question with the C# and .NET tags. 我注意到您已经用C#和.NET标记标记了这个问题。 In that case, you may be interested to learn that the UI Automation APIs have been wrapped in the .NET Framework . 在这种情况下,您可能有兴趣了解UI自动化API已包装在.NET Framework中

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

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