Vbscript 在QTP11中,如何用一个JavaButton测试多个按钮?

Vbscript 在QTP11中,如何用一个JavaButton测试多个按钮?,vbscript,qtp,Vbscript,Qtp,我想测试我的“方框图”中的按钮是一个java应用程序,我在我的对象存储库中添加了一个JavaButton,我想测试按钮的存在性,以及它们是否在默认情况下未启用。 在JavaButton的属性“label and attached text”中,我使用了一个正则表达式,但不能像快照中那样只使用一个JavaButton测试所有按钮(I2C1、I2C2等) 我想测试所有按钮: JavaWindow(“未命名的MicroXplorer*”)。JavaButton(“I2C1”).exist(1) Jav

我想测试我的“方框图”中的按钮是一个java应用程序,我在我的对象存储库中添加了一个JavaButton,我想测试按钮的存在性,以及它们是否在默认情况下未启用。 在JavaButton的属性“label and attached text”中,我使用了一个正则表达式,但不能像快照中那样只使用一个JavaButton测试所有按钮(I2C1、I2C2等)

我想测试所有按钮: JavaWindow(“未命名的MicroXplorer*”)。JavaButton(“I2C1”).exist(1) JavaWindow(“未命名的MicroXplorer*”)。JavaButton(“I2C2”).exist(1)

但是我不想在我的对象存储库中添加所有的JavaButton,我只想在测试中添加一个带有正则表达式的JavaButton。 先谢谢你


您不应该使用任何
JavaButton
对象,您可以
ChildObjects
获取与您的描述匹配的所有对象

Set Desc = Description.Create()
Desc("micclass").Value = "JavaButton"
Desc("label").Value = "I2C\d+" ' I'm not sure if label is the correct property...
Set Buttons = JavaWindow.ChildObjects(Desc)
For i = 0 To Buttons.Count - 1
    Buttons(i)._Whatever_
Next

您可以在对象存储库中使用单个
JavaButton
,然后在
index
属性上执行
SetTOProperty
,但是
ChildObjects
方法更自然。

您不应该为此使用任何
JavaButton
对象,您可以
ChildObjects
获取与您的描述匹配的所有对象

Set Desc = Description.Create()
Desc("micclass").Value = "JavaButton"
Desc("label").Value = "I2C\d+" ' I'm not sure if label is the correct property...
Set Buttons = JavaWindow.ChildObjects(Desc)
For i = 0 To Buttons.Count - 1
    Buttons(i)._Whatever_
Next

您可以在对象存储库中使用一个
JavaButton
,然后在
index
属性上执行
SetTOProperty
,但是
ChildObjects
方法更自然。

我就是这样做的,它可以工作!myLabel=“GPIO”如果是JavaWindow(“MicroXplorer Untitled”)。JavaButton(“标签:=”&myLabel)。存在然后msgbox“哇!Javawindow A标签带”&myLabel&“存在!”否则msgbox“失败!Javawindow A标签带”&myLabel&“不存在!”结束如果我这样做了,它就工作了!myLabel=“GPIO”如果是JavaWindow(“MicroXplorer Untitled”)。JavaButton(“标签:=”&myLabel)。存在然后msgbox“Woei!Javawindow A标签带有”&myLabel&“exists!”否则msgbox“Fail!Javawindow A标签带有”&myLabel&“not exists!”结束如果