How to select an item in a list box dynamically ?

Here is my scenario…
iam having a list box with different items in it…for example, im having country drop down in which it consists of items like
India,US,UK,Australia

how to select the desired item from the drop down dynamically
i.e suppose if user want to select India… how do i can prompt the user to select his desired country. if i prompt the user to enter the country name .how can i check whether that is existed in the list box or not…

please give me sample code snippet… i will be very thankfull.

You can prompt a user to enter a value using the ask command:

ask "What country do you want to select?"
put it into countryToSelect
Click "CountryDropDown"
Click (Text: countryToSelect, TextSize:"9", TextFont:"Arial")

(The text properties are just an example, you’d need to determine the actual text properties.)

The Click command serves to verify if the image exists (it fails if it doesn’t), but if you wanted to verify that the item exists in the list before trying to click it, you can use the imageFound() function:

if imageFound(Text: countryToSelect, TextSize:"9", TextFont:"Arial")
     Click foundImageLocation()
else
     LogError "entry  for" && countryToSelect && "does not exist"
end if

What if the selection you want needs to be selected after the menu has to be scrolled? See screen capture below. I am trying to figure out how I can emulate the same menu in the script run, so that the tester can select the choice “from” a pop-up menu, and then send the value of the selection to “it”.

Thanks

Mark

[quote=“EggplantMatt”]You can prompt a user to enter a value using the ask command:

ask "What country do you want to select?"
put it into countryToSelect
Click "CountryDropDown"
Click (Text: countryToSelect, TextSize:"9", TextFont:"Arial")

(The text properties are just an example, you’d need to determine the actual text properties.)

The Click command serves to verify if the image exists (it fails if it doesn’t), but if you wanted to verify that the item exists in the list before trying to click it, you can use the imageFound() function:

if imageFound(Text: countryToSelect, TextSize:"9", TextFont:"Arial")
     Click foundImageLocation()
else
     LogError "entry  for" && countryToSelect && "does not exist"
end if

[/quote]

There seem to be a couple of questions here. You can handle the scrolling with code like this:

repeat while not imageFound("itemToClick")
     Click "downArrow"
end repeat

I’m actually not clear on the second part of the question. Do you want to prompt the tester to choose a value that exists in the list and then use the tester’s choice to make the selection? If I have it right, then you could do that with something like this:

ask "Enter a value from this list: Dog, Cat, Bird, Fish"
put it into selection
repeat while not imageFound(Text:selection)
     Click "downArrow"
end repeat
Click foundImageLocation()

There’s no way to generate a dropdown list for the user to choose from – asking them to type a value from a given list is as close as you’re going to get.

This is what I suspected. One issue with this is, the dialogs that are generated with this code don’t auto expand top to bottom with longer lists of items.

[quote=“EggplantMatt”]I’m actually not clear on the second part of the question. Do you want to prompt the tester to choose a value that exists in the list and then use the tester’s choice to make the selection? If I have it right, then you could do that with something like this:

ask "Enter a value from this list: Dog, Cat, Bird, Fish"
put it into selection

There’s no way to generate a dropdown list for the user to choose from – asking them to type a value from a given list is as close as you’re going to get.[/quote]

How to get the count of all items in a dropdown/listbox , I just want to test the functionality for each and every item in the dropdown.

I can’t think of a good way of doing this – I can come up with some methods that could probably be made to work, but they are awkward and complicated. I’m going to have to leave this as a challenge to our other users.

@mappingman: I made a mistake with my “ask” command above. If you specify that you want the text to be part of the “message”, then you get a nicer display that expands as needed to display the text. Without specifying that, the text is assumed to be the “prompt”, which is just a single line:

put "fish" & return & "bird" & return & "dog" & return & "cat" & return & "panda" into choices
ask message choices prompt "Please enter a value from the list above:"

produces the panel shown below.