Ask a Question

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

RobvanBeest2
New Contributor

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 3
ebarbera
Staff

Hello @RobvanBeest2 - 

 

The Object Spy tool can be used to view the syntax of the options - for example:

https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select

ebarbera_0-1653406077643.png

 

Once you know the sytax i would suggest using a ClickItem method to select Australia - I do not believe a loop will be necessary. 

 

Let me know if you have additional questions. 


Emma

 

Marsha_R
Community Hero

You can use a While loop

https://support.smartbear.com/testcomplete/docs/keyword-testing/reference/statements/while-loop.html

 

and loop 'while mycomboboxvalue <> 'Australia' 

this will work if you are sure that Australia is in the combo box

 

if Australia might not be there, then you will have to add another value to check at the same time like the count of the combo box list

 

 


Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
npaisley
Staff

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-m...

 

I hope this helps!

 

 

 


Regards,
Nick

Solutions Engineer @ SmartBear
cancel
Showing results for 
Search instead for 
Did you mean: