Using Watir, how can I return the text of the currently selected item in a drop down list? It appears that getSelectedItems is deprecated.
Use selected_options() instead.
selected_options () Description:
Gets all the selected items in the select list as an array. An empty array is returned if the select box has no selected item. Output:
Array containing the selected items of the select list.
Source
The watir documentation also says you can do
browser.select_list.selected_options.map(&:text)
but this returns the text in an array, I guess it would be useful to do it this way if you have multiple items selected in the list.
['selected text']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With