完整的代码如下:
Function SelectRegExp(Obj,Patrn,Button,Offset) Dim NumOfItems,i,CurrentValue,regEx,ItemToSelect,oldFilter '初始化正则表达式 Set regEx=new RegExp regEx.pattern=patrn regEx.Ignorecase=false '区分大小写 ldfilter=Reporter.Filter '保存默认值 Reporter.Filter=2'仅发送错误 ItemToSelect=-1 '获取测试对象的 NumOfItems属性 NumOfItems=Obj.getroproperty("items count") For i=0 to NumOfItems-1 CurrentValue=Obj.GetItem(i) If regEx.test(CurrentValue)Then If (ItemToselect<>-1) Then SelectRegExp=-1 '表示匹配项不唯一 Reporter.Filter=oldFilter Exit function End If ItemToSelect=i End If Next Reporter.Filter=oldFilter '重置默认设置 '做出选择动作 If (ItemToSelect>=0) Then SelectRegExp=Obj.Select(ItemToSelect,Button,Offset) else SelectRegExp=-1 End If End Function Dialog("Login").WinEdit("Password:").Set "Cheers.lee" Dialog("Login").WinEdit("Edit").SetSecure "48d51f921459c0234cb35e05206c9141a5197c6a" Dialog("Login").WinButton("OK").Click Window("Flight Reservation").WinObject("Flight No:").Type "092208" Window("Flight Reservation").WinComboBox("Departure Time:").Select "London" Window("Flight Reservation").WinComboBox("Arrival Time:").Select "Los Angeles" Window("Flight Reservation").WinCheckBox("text:=FLIGHT").click RegisterUserFunc"WinList","select","SelectRegExp" Window("Flight Reservation").Dialog("Flights Table").Activate Window("Flight Reservation").Dialog("Flights Table").WinList("ListBox").select "19170.*" 'Window("Flight Reservation").Dialog("Flights Table").WinList("ListBox").Select"19170 LON 08:00 AM LAX 08:45 AM AA $100.50" Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click Window("Flight Reservation").WinEdit("Edit").Set "lihuichang" Window("Flight Reservation").WinRadioButton("Business").Set Window("Flight Reservation").WinButton("Insert Order").Click Window("Flight Reservation").Close |