51Testing软件测试论坛

标题: 正则表达式能不能用在下拉框的值选择? [打印本页]

作者: prodigyzh    时间: 2008-5-29 16:08
标题: 正则表达式能不能用在下拉框的值选择?
我有一个下拉框,
Browser("").Page("").Frame("").WebList("").Select "1000 Items"
我想让它表示成 1000*,怎么写?
能想到的我都试过了,都报错,对象不存在...
我使用对象库的。
作者: hsjzfling    时间: 2008-5-30 10:11
Someone solved this issue in sqaforums

Function IsRegEqual(s_Text, s_Pattern)
  Dim regEx, retVal ' Create variable.
  Set regEx = New RegExp ' Create regular expression.
  regEx.Pattern = s_Pattern ' Set pattern.
  regEx.IgnoreCase = True
  IsRegEqual = regEx.Test(s_Text)
End Function

Function SelectByText(objWebList,s_Text,b_RegExpression)
  Set obj_Options=objWebList.object.options
  i_Count =obj_Options.length - 1
  For i=0 to i_Count
    If b_RegExpression And IsRegEqual(obj_Options(i).text,"^"+ s_Text) Then
      obj_Options(i).selected=True
      Exit for
    Elseif Lcase(s_text)=Lcase(obj_Options(i).text) then
      obj_Options(i).selected=True
      Exit for
    End If
  Next
End Function

Function SelectByValue(objWebList,s_Value,b_RegExpression)
  Set obj_Options=objWebList.object.options
  i_Count =obj_Options.length - 1
  For i=0 to i_Count
    If b_RegExpression And IsRegEqual(obj_Options(i).value,"^" & s_Value) Then
      obj_Options(i).selected=True
      Exit for
    Elseif Lcase(s_text)=Lcase(obj_Options(i).value) then
      obj_Options(i).selected=True
      Exit for
    End If
  Next
End Function

Function SelectByIndex(objWebList,i_Index)
  objWebList.object.options(i_Index).selected=True
End Function

' for example
SelectByText Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebList("fromPort"),".*ond.*",TRUE
SelectByValue Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebList("fromPort"),"san.*francisco",TRUE
SelectByIndex Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebList("fromPort"),3
作者: hajiwon    时间: 2008-5-30 10:28
Browser("").Page("").Frame("").WebList("").Select " text:=1000"&".*"




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2