Watir / Ruby:如何在下拉列表中获取所选项的文本?

时间:2022-02-08 07:26:16

Using Watir, how can I return the text of the currently selected item in a drop down list? It appears that getSelectedItems is deprecated.

使用Watir,如何在下拉列表中返回当前选择的项的文本?似乎getselecteditem已被弃用。

2 个解决方案

#1


6  

Use selected_options() instead.

使用selected_options()。

selected_options () Description:

selected_options()描述:

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

#2


1  

The watir documentation also says you can do  

watir文档也说你可以这么做

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']

#1


6  

Use selected_options() instead.

使用selected_options()。

selected_options () Description:

selected_options()描述:

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

#2


1  

The watir documentation also says you can do  

watir文档也说你可以这么做

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']