Forum Discussion

lokwk216's avatar
lokwk216
New Contributor
2 years ago

interaction with multiple drop-down lists

Hello,

 

I am running Testcomplete 15.40.421. In my testing scenario, there are two drop-down lists on the same page. The items in the first list is dynamic, and the second drop-down list changes dynamically as well based on the selected value of the first drop-down list.

 

I want to record down the values in the second drop-down when selecting different items in the first drop-down, but am stuck at creating a loop for the first dynamic list. Is there a simple way to achieve this? 

 

Your help would be greatly appreciated!! Thank you.

 

 

  • I often need to capture dynamic values and I store them in an array, then access each array value for other reasons.  Here I pass in the drop down object to the function to capture the options within an array...

     

    function CaptureSelectBoxOptions(SelectBoxOptionsList) {
      const values = [];
      let TotalOptions = SelectBoxOptionsList.ChildCount;
      //Log.Message(TotalOptions, "", 0);
    
    
      for (let i = 0; i < TotalOptions; i++) {
        if (SelectBoxOptionsList.Child(i).contentText != "") {
          values.unshift(SelectBoxOptionsList.Child(i).contentText);
        }
      }
    
    return values; //Returns an array of the values from the select box.
    }


    You could then iterate through that array to click on each value so the second drop down populates, and capture the values in the same manner.  Or you could probably just add something like this to the if statement above to capture and click them at the same time:

    SelectBoxOptionsList.Child(i).Click();


    You may also need to refresh the TestComplete object tree cache to capture the newly populated values (from the second drop down) after clicking an option in the first drop down using something like this:

    Aliases.browser.PageName.DropDown2Name.Refresh();

      

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    You can you the split() method, which splits a string into an array of substrings. 

    Once you got the list of items, you can then iterate through the list and perform the necessary actions you want.

    • scottroutesmart's avatar
      scottroutesmart
      Occasional Contributor

      I often need to capture dynamic values and I store them in an array, then access each array value for other reasons.  Here I pass in the drop down object to the function to capture the options within an array...

       

      function CaptureSelectBoxOptions(SelectBoxOptionsList) {
        const values = [];
        let TotalOptions = SelectBoxOptionsList.ChildCount;
        //Log.Message(TotalOptions, "", 0);
      
      
        for (let i = 0; i < TotalOptions; i++) {
          if (SelectBoxOptionsList.Child(i).contentText != "") {
            values.unshift(SelectBoxOptionsList.Child(i).contentText);
          }
        }
      
      return values; //Returns an array of the values from the select box.
      }


      You could then iterate through that array to click on each value so the second drop down populates, and capture the values in the same manner.  Or you could probably just add something like this to the if statement above to capture and click them at the same time:

      SelectBoxOptionsList.Child(i).Click();


      You may also need to refresh the TestComplete object tree cache to capture the newly populated values (from the second drop down) after clicking an option in the first drop down using something like this:

      Aliases.browser.PageName.DropDown2Name.Refresh();

        

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Are you not able to capture the properties of contentText (or similar), which lists all the items within the control when expanded. Similar to this?

     

    • lokwk216's avatar
      lokwk216
      New Contributor

      Hi rraghvani, yes I can open the drop-down and capture the context inside, but I couldn't figure out how to simulate selecting the items one by one in a loop