Forum Discussion

gopster1283's avatar
gopster1283
Occasional Contributor
10 years ago

Selecting Combo Box items that are out of view

Hi guys,





So in several of our applications we have combo boxes that contain large number of items (like over 100). Now TestComplete in some cases cannot select items that are out of view. I understand that it is out view, but is there any way I can bring focus to that item and select it. Is there any other workaround?



I have two code snippets that I tried:




for each item in sItemList



  if Trim(item)=Trim(sEnterValue) Then



    oObj.ClickItem(x)



    Delay(1000)



    exit for



  End if

 x = x + 1



Next



in the code above I extract the item list from the wItemList property and the seperator (wListSepreator property), and loop through the list. If I find the required value (sEnterValue variable) then I click it. This works perfectly for items IN VIEW.oObj is the comboBox object.





iItemCount = oObj.Items.Count

 for x = 0 To iItemCount - 1

        If Trim(LCase(oObj.Items.get_Item(x).OleValue))=Trim(LCase(sEnterValue)) Then

          'oObj.Items.Refresh

          oObj.ClickItem(oObj.Items.get_Item(x))

          Delay(1000)

          Exit for

        End If

      Next





In this second code snippet, I am trying to get the item directly using the get_Item property. It seems to work for items in view as well as for a few items out of view,   but definelty NOT for items that are say 100+ down the list.



I see there is a navigatetoItem function as well as a set focus function for the combo box object. I am not sure what to pass in for those functions. I tried looking around the MSDN library but couldnt follow the liuterature there. My final solution would be to use the send keys. But, I would rather use that as a very last resort!!



We have a .Net application so the objects are of System.Windows.Controls classes.



We also tried record and replay, but still the item couldnt be selected.


3 Replies

  • I wonder if a call to


    scrollIntoView() on the object you are about to click might help?



    So obj.scrollIntoView() before you call obj.Click().



    Not sure if it will help in your case but I have used it in similar situations.  Easy to give it a try!


  • gopster1283's avatar
    gopster1283
    Occasional Contributor
    Tony:



    Unfortunately I don't see that function listed out there in the methods tab.



    Here is a list of the scrollable functions for the combobox object:



    ComboBox object:

    DoAutoScroll

    DoAutoScroll_2(startingItem As Object)



    The combox box item object also does not have any scrollable functions.



    Now we do have a scroll bar for users to navigate to the item they require, but I tried getting that scroll bar via record-replay but couldn't.

  • Manfred_F's avatar
    Manfred_F
    Regular Contributor
    Hi,



    I had a similar issue with our listboxes.

    TC can't directly read the itemlist, so I have to use textobjects to Access the items. When iterating the testobjects, I only get the currently depicted ones. I solved this using Keyboard Input (Home, PgDn) to iterate the listbox's list pages.



    Regards,



    Manfred