hi,
Using Watir,I want to print the selected element from select_list, how
could I do that?
hi,
Using Watir,I want to print the selected element from select_list, how
could I do that?
This is the usual syntax to print the selected option:
print browser.select_list(:id => ‘my_list’).value
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
Hi Joel P.
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?
hi Joel P.,
That’s the great idea, thank you very much.
RAJ
hi Joel P.,
It works perfectly, Thank you very much Once again.
RAJ
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs