Forum Discussion

brian_kratsch's avatar
brian_kratsch
Contributor
10 years ago
Solved

Selecting unique value from drop down list with duplicates

Background: Keyword Test user, very little coded experience but I can usually follow examples Issue: I have run into a HTML Select object (ObjectType Select) that has duplicate values in the...
  • HKosova's avatar
    10 years ago
    Hi Brian,



    You can also use a custom ClickItem function to click the Nth matching item. For example (assuming your project uses JScript):



    /*

    Selects the Nth duplicate item from the combo box.



    Parameters:

    ComboBox - the combo box object.

    Label - the item text.

    Index - the index (from 1) of the duplicate item to select.

    */

    function ClickItem(ComboBox, Label, Index)

    {

      var ind = 1;

      for (var i = 0; i < ComboBox.wItemCount; i++)

      {

        if (ComboBox.wItem(i) == Label)

        {

          if (ind == Index)

          {

            ComboBox.ClickItem(i);

            return;

          }

          else

            ind++;

        }

      }

    }



    In your keyword test, use the Run Script Routine operation to call this ClickItem function with the following parameters:

    ComboBox: Aliases.browser.<page_name_and_name_of_the_select_element>

    Label: item text

    Index: 2