Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to select the drop down option by searching for partial text
#1
Not Solved
Hi all,

I am new to QTP and trying to learn. I would like to know how to select a specific option that matches a partial text from a drop down using QTP.

The drop down in my application consists of more than 100 options and I need qtp to select some options based on the string values stored in a spreadsheet. I have a list of string values and need to compare this strings with the options in the drop down and select the one that matches with the string. These string values are only partial texts from the drop down values.

Ex. If the drop down options are
2015 Jan
2015 Feb
2015 Mar
2014 Jan
2014 Feb
2014 Mar

and I want to select any month from 2015 or 2014. So I want to search by partial text 1. 2015 2. 2014.

Any help, ideas are great appreciated. Thanks in advance.
Reply
#2
Not Solved
Please try the below code. Here the oObjectRef is the string reference of the object (dropdown object), sVerifyListItem is the partial string that you want to check

Code:
Dim sStringExist, i, j, iMin, iMax, sActItemList
    

    sItemArray = Split(sVerifyListItem," ")

    iMinArray = LBound(sItemArray)
    iMaxArray = UBound(sItemArray)

    sStringExist = "N"
    
    sItemCount = oObjectRef.GetROProperty("items count")
    
    For i = 1 to sItemCount

        sActItemList = oObjectRef.GetItem(i)

        For j = iMinArray to iMaxArray
            nPos = Instr(sActItemList,sItemArray(j))
            If nPos>=1 Then
                sStringExist = "Y"
            Else
                sStringExist = "N"
                Exit For
            End If
        Next

        If sStringExist = "Y" Then
            oObjectRef.Select sActItemList
            oObjectRef.FireEvent("onFocus")
            
            Exit For
        End If

    Next
Reply
#3
Not Solved
Thanks for the reply. I tried this but would not work. I'm getting an error message when I create ObjectRef. Does qtp support this feature
Code:
ObjectRef = Browser(...).Page(...).WebList(...)
I am able to use get item count, get item etc.. though.
Reply
#4
Not Solved
If GetItemCount and GetItem is not working for the weblist, I've other idea.

First check whether are you are able to get the text of the selected item by obj.getroproperty("text") and you are able to select the item of the weblist by Up and Down arrow keys, if yes then follow this

Code:
ptrn=DataTable.value("Column",dtlocalsheet)
Set re=New RegExp
re.pattern=ptrn
re.ignorecase=True
re.global=False
For i=1 to 100
Src=obj.getroproperty("text")
Set a=re.execute(Src)
If a.count>0 then
Exit for
Print Src&" selected"
else
obj.Type micdwn
End If
Next

Note: Not sure it works but it worked for me in winobjects
Reply
#5
Not Solved
Thanks for the reply.

I found an alternative way to solve this. Here is what I did.

1. I pulled all the list items from the drop down and stored into a String variable of array type using Split method.
2. I compared each of these list items with the text string I have using Instr method by adding a loop.
3. If found I then checked the position if it is greater than or equal to 1. And if true then select the list item with the count that matches in the loop statement.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need to Validate Text filed is blank after clicking on the Text box balak89 3 4,968 09-13-2015, 12:06 AM
Last Post: ADITI1992
  Web Element: Not able to select value from drop down in Web Element. Rajeev 4 5,349 08-04-2015, 06:03 PM
Last Post: kbhargava505
  Click on drop down and select second option using HP UFT Tusharguru99 2 6,724 07-30-2015, 06:06 PM
Last Post: Neetha
  Drag and drop issue excellentpawan123 0 2,755 01-13-2015, 05:04 PM
Last Post: excellentpawan123
  Drop down list class is a link thotamurali 2 4,227 08-22-2014, 05:48 PM
Last Post: thotamurali

Forum Jump:


Users browsing this thread: 1 Guest(s)