测试交流天地

用QTP的描述性编程高亮显示任意对象

上一篇 / 下一篇  2011-07-24 09:52:05 / 个人分类:QTP

这里运用描述性编程实现高亮显示计算器中的0到9的按钮对象
把以下代码拷到QTP中,点“运行”,看看效果。
注:本程序windowsXP下的计算器演示,若使用windows 2000的计算器无效。


SystemUtil.Run "C:\WINDOWS\system32\calc.exe","","C:\WINDOWS\system32","open"
For i =0 to 9
HighlightAll Window("regexpwndclass:=SciCalc").WinButton("text:=" & cstr(i) )
Next


Sub HighlightAll(TestObject)

       Dim Parent, Desc, Props, PropsCount, MaxIndex, i, Objs
       If IsEmpty(TestObject.GetTOProperty("parent")) Then
              Set Parent = Desktop
       Else
              Set Parent = TestObject.GetTOProperty("parent")
       End If
       Set Desc = Description.Create
       Set Props = TestObject.GetTOProperties
       PropsCount = Props.Count - 1
       For i = 0 to PropsCount
              Desc(Props(i).Name).Value = Props(i).Value
       Next
       Set bjs = Parent.ChildObjects(Desc)
       MaxIndex= Objs.Count - 1
       For i = 0 to MaxIndex
              Objs.Item(i).Highlight
       Next

End Sub


TAG:

 

评分:0

我来说两句

Open Toolbar