views:

1112

answers:

5

I write automated test with Ruby(Selenium framework) and I need to know how can I select an option from drop-down list.

Thanks in advance!

A: 

It sounds like you are writing a functional test here. Selecting it probably won't do you much good on its own. You need to submit the form in order to test the controller. :) It might help people answering to know which testing framework you are using, because there are several to choose from. If you are using RSpec, check out this screencast.

Hope that helps anyway.

Aram Verstegen
A: 

Aside from functional tests, if you're looking for something that acts a bit more like the real app, have a look at WebRat. For non-AJAXed integration tests, it has a very nice DSL for selection your DOMs and taking appropriate actions against them. (link-clicking form-filling etc.).

On the other hand if your App is an external Web App that you just want to do acceptance tests on, you can also check Selenimum or Watir.

Note that WeRat is heavily web framework based where as Selenimum and Watir use the browser to interact with your web app directly (like a real user).

newtonapple
A: 

I think you want this command :-

select(selectLocator, optionLocator)
  • selectLocator identifies the drop down list
  • optionLocator identifies the option within the list
floehopper
+1  A: 

building on floehopper's answer:

selenium.addSelection(locator, value)
or
selenium.select(locator, value)

You almost certainly want "id=my_select_box_id" (with the quotes) for locator, though other CSS selectors will work. value is the literal text value (not the display value) of the option to be selected.

James A. Rosen
A: 

Easiest way of doing this: select(selectLocator,optionLocator) as suggested above.

selectLocator: name or xpath for dropdown object optionLocator: name or xpath for dropdown option to be selected

E.g. @selenium.select "Language", "label=Ruby"

Gunjan