Selected element from select_list

hi,

Using Watir,I want to print the selected element from select_list, how
could I do that?

···

--
Posted via http://www.ruby-forum.com/.

This is the usual syntax to print the selected option:

print browser.select_list(:id => 'my_list').value

···

--
Posted via http://www.ruby-forum.com/.

Hi Joel Pearson

Thank you for your reply, When I use your statement to print the
selected values "browser.select_list(:id => 'my_list').value" it is
printing the number not the text, If I give ""browser.select_list(:id =>
'my_list').text" then it is printing all the values of select_list not
the selected value. What should I do now to print the selected value?

···

--
Posted via http://www.ruby-forum.com/.

If you want the text instead of the value, it's a bit more complex.
Select lists can have multiple options. In order to accommodate this
behaviour, the syntax for all the selected options is
"selected_options".

list.selected_options

Because selected_options is an array, you'll then want the first option
in your case.

list.selected_options.first

Because an "option" is actually an object on the page, you'll want to
extract its text specifically.

list.selected_options.first.text

···

--
Posted via http://www.ruby-forum.com/.

hi Joel Pearson,

That's the great idea, thank you very much.

RAJ

···

--
Posted via http://www.ruby-forum.com/.

hi Joel Pearson,

It works perfectly, Thank you very much Once again.

RAJ

···

--
Posted via http://www.ruby-forum.com/.