|
这里运用描述性编程实现高亮显示计算器中的0到9的按钮对象。
把以下代码拷到QTP中,点“运行”,看看效果。
注:本程序以windows XP下的计算器演示,若使用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 Objs = Parent.ChildObjects(Desc)
MaxIndex= Objs.Count - 1
For i = 0 to MaxIndex
Objs.Item(i).Highlight
Next
End Sub
[ 本帖最后由 songfun 于 2007-5-15 20:58 编辑 ] |
|