WebList使用正则表达式选择某项目(脚本)
上一篇 /
下一篇 2012-01-13 22:57:19
/ 个人分类:QTP/UFT
Tarun Lalwani在sqaforums中有篇帖子提到了在weblist中使用正则表达式来选择某项目51Testing软件测试网%Y9vr9lR+p&t
http://www.sqaforums.com/showflat.php?Number=216204
脚本及示例如下:
Function IsRegEqual(s_Text, s_Pattern)51Testing软件测试网~c}L:Rt+a
Dim regEx, retVal ' Create variable.51Testing软件测试网a8b(uG/[;U
Set regEx = New RegExp ' Create regular expression.
_:{/NIHt$Z0regEx.Pattern = s_Pattern ' Set pattern.
"|3y,O,i;yFA(Cb0regEx.IgnoreCase = True51Testing软件测试网:oU N dM5D1]
IsRegEqual = regEx.Test(s_Text)
E'x7Wu
pfK g yX(E)x0End Function
lm5|\
gR z&P&^051Testing软件测试网iL)HUI.O
Function SelectByText(objWebList,s_Text,b_RegExpression)51Testing软件测试网1?/ER s[
~!CY4O
Set obj_Options=objWebList.object.options
6z/v
Mw)q
q0i_Count =obj_Options.length - 1
"{,iBex
p7vc;O3g4v0For i=0 to i_Count51Testing软件测试网Dy[L(b6Rh+T
If b_RegExpression And IsRegEqual(obj_Options(i).text,"^"+ s_Text) Then
4C${k4^0[5o6Pk0obj_Options(i).selected=True
-HTxi `;z0Exit for
!`+mf#[6kq&Ug V(KFp;X0Elseif Lcase(s_text)=Lcase(obj_Options(i).text) then51Testing软件测试网bE'd:[g[qk!^Q
obj_Options(i).selected=True51Testing软件测试网
h?C~w7]G
l5D
Exit for
3Z']Q'Bi9M(R)O"V0End If
6Rv F8On p0Next
l'Ey3V%wq0End Function
%l V]&Se%L&a3y%^x051Testing软件测试网"M0u6CI4oO.f eF/|o
Function SelectByValue(objWebList,s_Value,b_RegExpression)
lx;dhg&P*ezx0Set obj_Options=objWebList.object.options
m)pzK'}C`I0i_Count =obj_Options.length - 1
)Q:Sy7c\{0For i=0 to i_Count51Testing软件测试网+au1[yR-V \9d2e%n9k
If b_RegExpression And IsRegEqual(obj_Options(i).value,"^" & s_Value) Then
8hM&d#i@*F$\0obj_Options(i).selected=True
h
c'HH/\? sB.w0Exit for51Testing软件测试网M-wHT1Rv
Elseif Lcase(s_text)=Lcase(obj_Options(i).value) then51Testing软件测试网-u7d$V6JeZj)FL
obj_Options(i).selected=True
3nU3b i&j+nY0Exit for
p+m!l@-o|#r6ytb vT%d0End If
N#N,?1}'c%W3R1}b
A0Next51Testing软件测试网?!bJw;iqTg.H]X
End Function
&z&M#\!tK0
|5`qzG&i0Function SelectByIndex(objWebList,i_Index)
Z.Vt&q(A!c0objWebList.object.options(i_Index).selected=True51Testing软件测试网1~y!F1`
mu
_t
End Function51Testing软件测试网SC.J:p"rD
N&k6_c:W9sP;O0示例:51Testing软件测试网
sg'Z$H*m q(O
SelectByText Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebList("fromPort"),".*ond.*",TRUE
u]"r+Ku0SelectByValue Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebList("fromPort"),"san.*francisco",TRUE51Testing软件测试网s h3VZ,zg5|F
SelectByIndex Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebList("fromPort"),3
F4a4QAZ0H0
51Testing软件测试网i6v+Gt~d
我们更多时候还是习惯使用UserFunc
Function Selectregex(objWebList,s_Text,b_RegExpression)
kPas&{%d}0
51Testing软件测试网H@ Z v)mrX'O$z
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
51Testing软件测试网*T{
f`s#n
RegisterUserFunc "WebList", "Selectregex", "Selectregex"
收藏
举报
TAG: