--WebList QTP those things with regular expressions

Function IsRegEqual(s_Text, s_Pattern)
  Dim regEx, retVal ' 变量
  Set regEx = New RegExp ' 创建正则表达式 .
  regEx.Pattern = s_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
下面是例子:
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

 

 

 

The second method is:

'When Select WinList support option to use regular expressions
Function RegExpSelect (objWinList, strPattern)
Dim objRegExp, arrAllItems, intIndex
' create a regular expression object, set the case-sensitive
the Set objRegExp = New RegExp
objRegExp.IgnoreCase = False
objRegExp.Pattern = strPattern
'text to take all options under WinList, assigned to the array
arrAllItems = Split (objWinList.GetROProperty ( "All items"), vbLf)
' array of options for traversing
the For the to the UBound intIndex = 0 (arrAllItems)
  'judges whether the expression matches the current option is selected to match it, or continue to cycle
  the if objRegExp.Test (arrAllItems (intIndex)) the then
   objWinList.Select intIndex
   Reporter.ReportEvent micPass, "RegExpSelect Successful", "Pattern =" & strPattern & "First Item = matched" &arrAllItems(intIndex)
   Set objRegExp = Nothing
   Exit Function
  The If End
the Next
'if all options have been traversed can not match, an error is reported does not match the write log
Reporter.ReportEvent micFail, "RegExpSelect Failed", "No Item Matched, Pattern =" & strPattern
End Function

 

Here is the QTP registered in your own functions:

'The RegExpSelect function of registration methods to WinList go
RegisterUserFunc "WinList", "RegExpSelect", "RegExpSelect"
' method in use RegExpSelect WinList, select the first option to be able to meet the expression
'such as here hoping to automatically select a morning between 10:00 to 12:00 and Portland to Los Angeles flight prices below $ 180
Window ( "flight Reservation"). Dialog ( "flights Table"). WinList ( "From"). RegExpSelect "\ d + POR 1 [01 ]: [0-5] [0-9] AM LAX \ d {2}: \ d {2} [AP] M \ w + \ $ 1 [0-7] \ d \ \ d {2} ".

Reproduced in: https: //www.cnblogs.com/alterhu/archive/2012/03/25/2416999.html

Guess you like

Origin blog.csdn.net/weixin_33755557/article/details/94029488