WebList使用正则表达式选择某项目(脚本)
上一篇 /
下一篇 2012-01-13 22:57:19
/ 个人分类:QTP/UFT
Tarun Lalwani在sqaforums中有篇帖子提到了在weblist中使用正则表达式来选择某项目51Testing软件测试网x5yn,f-k
http://www.sqaforums.com/showflat.php?Number=216204
脚本及示例如下:
Function IsRegEqual(s_Text, s_Pattern)
?T-D&?#i0Dim regEx, retVal ' Create variable.51Testing软件测试网(G}6e-TP]Zr;Z
Set regEx = New RegExp ' Create regular expression.51Testing软件测试网I,e{-z2t1H-gT'v
regEx.Pattern = s_Pattern ' Set pattern.
$k2Z#CN7n&dh] i0regEx.IgnoreCase = True51Testing软件测试网.kwzn0x6pb&I
_
IsRegEqual = regEx.Test(s_Text)51Testing软件测试网@'\eB*vl _'m;W;R
End Function51Testing软件测试网hUE;hc,lIp\g
51Testing软件测试网3T4A9L&nB/u
Function SelectByText(objWebList,s_Text,b_RegExpression)51Testing软件测试网ua*d~
N0{,Z*zy
Set obj_Options=objWebList.object.options
$_M_~`(i#e1C0i_Count =obj_Options.length - 151Testing软件测试网qD0^!KR`@C
For i=0 to i_Count
bhf7J)M0If b_RegExpression And IsRegEqual(obj_Options(i).text,"^"+ s_Text) Then
r
p v E
q f/p4Y0obj_Options(i).selected=True51Testing软件测试网2[8T }8E`yc
Exit for
f r+C
t
C{S/Y0Elseif Lcase(s_text)=Lcase(obj_Options(i).text) then
;FbpVyC#M$c0obj_Options(i).selected=True
'}"a$ErXD0Exit for
B2yBHW|?G!?0End If51Testing软件测试网6P R4tM8x1z P!x1Kil4G
Next51Testing软件测试网|#t s WXIw u
End Function
O?ou)]2nP9~ _(J051Testing软件测试网
e`k |W7pI T%X%F
Function SelectByValue(objWebList,s_Value,b_RegExpression)
;P+d"`4k]0Set obj_Options=objWebList.object.options
a\4r.@-jH2L9UA7vw0i_Count =obj_Options.length - 151Testing软件测试网PE s*ll6t f
For i=0 to i_Count
#[:o
Jg0F|bX0If b_RegExpression And IsRegEqual(obj_Options(i).value,"^" & s_Value) Then51Testing软件测试网0J0]5c(b1Q0d/yg
obj_Options(i).selected=True
*|b'Q4O Y0Exit for
w_&YR0y;a$m!`0Elseif Lcase(s_text)=Lcase(obj_Options(i).value) then
$Dj"U6?rMdZ0obj_Options(i).selected=True51Testing软件测试网.Hz
cd6L]y
Exit for
nG|L'_5i{6VK0End If
2M'[Q"dD#t?)F
q'?0Next
yL&F5^j7{]0End Function51Testing软件测试网$? Lu\T;]B[U7D
y#u"l0p7c"}0sh3p#K#K0Function SelectByIndex(objWebList,i_Index)
K.R|7wI l:R0[t2sW0objWebList.object.options(i_Index).selected=True
/J3za P
G&EcR9b0End Function
TJ.el*[x
WR#|051Testing软件测试网1wQw0W
l2G]
示例:
co.VJ
I4K$G7]H0SelectByText Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebList("fromPort"),".*ond.*",TRUE51Testing软件测试网Y7L7A!SZ_:}d!IQ
SelectByValue Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebList("fromPort"),"san.*francisco",TRUE51Testing软件测试网c i2X O(G?aua
SelectByIndex Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebList("fromPort"),3
$z0E:I0X:t#^W0
51Testing软件测试网,u*G q&z9CU
我们更多时候还是习惯使用UserFunc
Function Selectregex(objWebList,s_Text,b_RegExpression)
51Testing软件测试网 E Y{4@E*g1I
Am:T2L
51Testing软件测试网+VFmsX)Q
i_count=objWebList.getroproperty("items count")
For i=1 to i_Count
getitems=objWebList.getitem(i)
If b_RegExpression And IsRegEqual(getitems,"^"+ s_Text) Then
objWebList.select i-1
Exit for
Elseif Lcase(s_text)=Lcase(getitems) then
objWebList.select i-1
Exit for
End If
Next
End Function
"aq?-Rl0
RegisterUserFunc "WebList", "Selectregex", "Selectregex"
收藏
举报
TAG: