Micro Focus QTP (UFT) Forums
How to select the drop down option by searching for partial text - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: How to select the drop down option by searching for partial text (/Thread-How-to-select-the-drop-down-option-by-searching-for-partial-text)



How to select the drop down option by searching for partial text - Neetha - 07-30-2015

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.


RE: How to select the drop down option by searching for partial text - sporandla - 07-31-2015

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



RE: How to select the drop down option by searching for partial text - Neetha - 08-03-2015

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.


RE: How to select the drop down option by searching for partial text - kbhargava505 - 08-04-2015

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


RE: How to select the drop down option by searching for partial text - Neetha - 08-04-2015

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.