Forum Discussion

s5h's avatar
s5h
Contributor
12 years ago

Selecting an item from combobox/dropdownlist

Hi 



I was wondering is it possible to select an item based on caption/index from a combobox/dropdown in a keyword test? 

My combobox did not have the ClickItem method mentioned in other posts so I added it in the Object mapping settings Win32Controls/Combobox and I now can use the Click Item method.

The problem I am having is this:

I click on the combobox and it opens the dropdown. I then want to click on an item based on the caption, so have combox.clickitem("City") but it will not click on anything and the error posted to the log is "Drop down box cannot be opened".



I also tried a For..loop which iterates through the list and if the displaytext = myparamter then click on it. This isn't working for me. 



The dropdown list maps to a different location to the combobox. So should I be using clickitem on the combobox or the dropdown list. 



Hope you can help 
  • Hi Siobhan!

    Please check again your mapping item, you can find item's menthods by Method tab in Advanced view to make sure that the methods are avaiable.

    Hope this code can help you:



    /**Looking for a filter name in Filter Name dropdownlist*/

    function Verify_Filter_Name_Exist_In_List(filter_name)

    {

      try

      {    

        var Obj=Aliases["pageInventoryDetailReport"]["list_Filter_Name"];//list_FIlter_Name appears after user clicked on combobox

        var i;

        if(!Obj["VisibleOnScreen"])

        {

          Aliases["pageInventoryDetailReport"]["cb_Filter_Name"]["Click"]();// cb_Filter_Name is a combo box

        }   

        for(i=0;i<Obj["wItemCount"];i++)

        {

          if(Obj["wItem"](i)==filter_name)

          {

            return true;

          }     

        }

        return false;

      }catch(ex)

      {

        Messageshow=ex["description"];

        return false;

      }

    }
  • krupa_luke's avatar
    krupa_luke
    Occasional Contributor
    Hi Siobhan,



    what's the type of your application you are testing? If it is web, you can use xpath for mapping any comboBox / weblist item. 
  • anhhao_nguyentr's avatar
    anhhao_nguyentr
    Occasional Contributor
    Hi Siobhan!

    Please check again your mapping item, you can find item's menthods by Method tab in Advanced view to make sure that the methods are avaiable.

    Hope this code can help you:



    /**Looking for a filter name in Filter Name dropdownlist*/

    function Verify_Filter_Name_Exist_In_List(filter_name)

    {

      try

      {    

        var Obj=Aliases["pageInventoryDetailReport"]["list_Filter_Name"];//list_FIlter_Name appears after user clicked on combobox

        var i;

        if(!Obj["VisibleOnScreen"])

        {

          Aliases["pageInventoryDetailReport"]["cb_Filter_Name"]["Click"]();// cb_Filter_Name is a combo box

        }   

        for(i=0;i<Obj["wItemCount"];i++)

        {

          if(Obj["wItem"](i)==filter_name)

          {

            return true;

          }     

        }

        return false;

      }catch(ex)

      {

        Messageshow=ex["description"];

        return false;

      }

    }
  • s5h's avatar
    s5h
    Contributor
    Hi 



    Thanks for the reply. 



    I have figured how to do it through KDT using a for loop to iterate through the items and select the item based the on the parameter the user passes to the test 



    Thanks again 
  • surabhi_agarwal's avatar
    surabhi_agarwal
    Occasional Contributor
    Hi Can you please let me know the KDT way to iterate in loop. I am facing the same issue.