如何在qtp中访问运行时对象?

发布于 2024-09-03 20:27:38 字数 128 浏览 6 评论 0原文

我们有一个函数可以访问标准 Windows 应用程序中的两种类型的控件,例如按钮和列表框。该函数仅使用控件名称作为参数,因此 qtp 无法理解它是什么类型的控件。如何解决这个问题?编写 2 个独立的函数 - 1 个用于按钮和一个另一个列表框?

We have a function which accesses two types of controls like button and list box in standard windows app. The function uses only the control name as arguments, so there is no way qtp could understand what type of control it is. how to resolve this? Write 2 separate functions- 1 for button & another for list box?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半透明的墙 2024-09-10 20:27:38

这取决于您想要对对象执行什么操作,如果您想要执行所有 WinObjects 通用的操作(例如 ClickGetROProperty)你可以这样做,如果它特定于不同的测试对象,你将必须有不同的方法(或者至少在内部以不同的方式对待它)

科学模式下的 Calc.exe 示例:

Public Function Click(ByVal Name)
   Window("text:=Calculator").WinObject("text:=" & Name).Click
End Function

Click "8" ''# This is a button
Click "Oct" ''# This is a radio button

运行后结果是10(八进制中的 8)


另一种方法是使用 ChildObjects 来获取与此属性匹配的所有对象(在本例中是一个),检查什么它的对象类型 (GetROProperty("micclass")) 并打开它来执行您的特定操作。

It depends what you want to do with the object, if you want to do something that is common to all WinObjects (e.g. Click or GetROProperty) you can do that, if it's specific to different test objects you'll have to have different methods (or at least treat it differently internally)

Example for Calc.exe in scientific mode:

Public Function Click(ByVal Name)
   Window("text:=Calculator").WinObject("text:=" & Name).Click
End Function

Click "8" ''# This is a button
Click "Oct" ''# This is a radio button

After running the result is 10 (8 in octal)


Another way to do this would be to use ChildObjects in order to get all the objects that match this property (in this case one), check what type of object it is (GetROProperty("micclass")) and switch on that to perform your specific actions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文