QTP Forums

Full Version: Regular expression in Select
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

A very simple action...
I have a JavaList with one of the values "TestNumber1"

So I do
JavaList("name").Select "TestNumber1"
and it works

but I would like to make it shorter like:
.Select "Test.*"
but it doesn't work?!

In OR this kind of syntax is OK... but not in string

Thanks,
Hi Maverick,

Yup i will agree with you, that the select method won't work with regular expression but you can write function/method to select the listitem even with regurlar expression.

Please find the below LOC and open the Google page and then paste and run the code.
'------------------------------------------------------------------------------------
Browser("name:=Google").Page("title:=Google").Link("name:=Preferences").Click
'I want to select "Hungarian" from the list box.
WLSelection Browser("name:=Preferences").Page("title:=Preferences").WebList("name:=hl"),"Hung.*"

Function WLSelection(strLBPath,strLBitem)
Dim LBitem,allitems,itemsnum
If instr(strLBitem,".*")>0 Then
LBitem=Split(strLBitem,".*")
allitems=strLBPath.GetROProperty("all items")
allitems=split(allitems,";")
For itemsnum=0 to ubound(allitems)-1
If instr(allitems(itemsnum),LBitem(0))>0 Then
strLBPath.Select itemsnum
Exit for
End If
Next
Else
strLBPath.Select strLBitem
End If
End Function
'----------------------------------------------------------------------------------------
Let me know if you need any more info.
Hello,

Thanks a lot. I will implement this function... :-)
Reference URL's