Ask a Question

How to check whether drop-down contain duplicate values or not?

SOLVED
DevPerera
Occasional Contributor

How to check whether drop-down contain duplicate values or not?

Hi All,

 

I want to know how to check whether drop-down contain duplicate values or not?

I am using Testcomplete version 11.

Also I am uing VB scripts.

My appraoch is first creat an array with all the drop-drown value, then find array contain any duplicate value or not.

 

I try to creat an array with dropdown values, but I am getting an error saying type mismatch.

For j = 0 To MyObject.wItemCount
MyArray(j) = MyObject.wItem(j)
Next

 

..................

Thanks

Dev

4 REPLIES 4
AlexKaras
Community Hero

Hi,

 

My guess is that wItem(j) is an object, so you must change

MyArray(j) = MyObject.wItem(j)

to

Set MyArray(j) = MyObject.wItem(j)

 

Also, if the drop-down supports a property that contains a complete list of all its values, you may consider using regular expressions (with HISUtils object in TestComplete) to check for the duplicates. The implementation and performance with regular expressions may be better.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
DevPerera
Occasional Contributor

Hi Alex,

 

Thanks for the reply, but I didnt know how to use "HISUtils" to find duplicate values.

If you can share some code example its whould be great help for me.

 

.............

Thanks

Dev

http://support.smartbear.com/viewarticle/71165/

 

Also, as Alex says, many dropdowns have a property containing all selections, rather than a series of objects you have to check in array.

 

Something like:

 

<list>.AllValues() = "Opt 1|Opt 2|Opt 3"

 

Or something along those lines. Just the selection text with some sort of separator. All in one string. Much easier to check.

DevPerera
Occasional Contributor

Hi Colin,

 

Thanks for your reply.

However I found a solution from some other site, written in VB.

 

Following is my code.

Sub Check_duplicate()
listcount = myselectobject.wItemCount
listcount = listcount - 1
listone = myselectobject.wItemList
Log.Message "select object list; " & listone
aList = split(myobj1,";")
For x = 0 To listcount
If InStr(sNewList,(aList(x) & ";")) <= 0 Then
sNewList = sNewList & aList(x) & ";"
End If
Next
listtwo = Left(sNewList,Len(sNewList)-1)
Log.Message "select object list; " & listtwo
If listone <> listtwo Then
Log.Message "duplicate found"
Else
Log.Message "No duplicate found"
End If

End Sub

 

...................

Thanks

Dev

cancel
Showing results for 
Search instead for 
Did you mean: