Forum Discussion

RobvanBeest2's avatar
RobvanBeest2
New Contributor
2 years ago

using a loop to select a certain value of a combo box

Hi, In TestComplete a want to select a certain value of a combobox.with country names in it I want to do that with a loop. So want to search in the combobox until I find de country "Australia" I don't think it is a data driven loop, because the value I need is not in a tabel or excel document but from a combobox in a screen. I cannot find how the syntax looks like.

3 Replies

  • Hi RobvanBeest2,

     

    Another solution would be to use the 'Find' method to search through your comboBox for designated data, store the object to a variable then perform any required actions on that variable.

     

    Here is an example script in Python;

    def findChild():
      #navigate to the w3c example page
      Browsers.Item[btChrome].Navigate("https://w3c.github.io/aria-practices/examples/combobox/combobox-select-only.html")
      browser = Aliases.browser
      
      #click on the comboBox to open it for child object detection  
      browser.pageSelectOnlyComboboxExampleWai.labelCombo1Label.panelFavoriteFruit.Click()
      
      #spy the entire comboBox and create a variable that hold the comboBox object itself
      box = Aliases.browser.pageSelectOnlyComboboxExampleWai.FindElement("#listbox1")
      
      #search through all the Child objects of the comboBox and click on one that has Apple as the contentText
      child = box.Find("contentText", "Apple", "10")
      child.Click()
    

     

    And here is the document for the 'Find' method;

    https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/find-method.html

     

    I hope this helps!