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

Nin*_*Cat 4 ruby watir

使用Watir,如何在下拉列表中返回当前所选项目的文本?似乎不推荐使用getSelectedItems.

Mah*_*oud 7

请改用selected_options().

selected_options()描述:

获取选择列表中的所有选定项目作为数组.如果选择框没有选定项,则返回空数组.输出:

包含选择列表的选定项的数组.

资源

  • 我正在使用Watir-Webdriver,我得到了这个:[#Watir :: Option:0x1d07556be located = true selector = {:element =>(webdriver element)}>].得到文本真的很好.有帮助吗? (2认同)
  • @blizzyb,使用select_element.selected_options.first.text (2认同)