Turning a select_list options into a string array in watir-webdriver?

柔情痞子 提交于 2019-12-03 21:19:41

There's no method doing exactly what you want, but a more concise version would be:

selectList = $browser.select_list(:id,"srch-status-select")
selectContent = selectList.options.map(&:text)

Have you tried the .options method? If I'm reading the RDOC for Watir-webdriver correctly, it should return a collection with all the options in the select list.

An alternate way to do this using loops instead of .map is:

elems = Array.new
values = Array.new
elems = @b.select_list(:id => "selectListId").options
0.upto(elems.length - 1) do |i|
    values.push elems[i].text
end

then to display the options

0.upto(values.length - 1) do |i|
    puts values[i]
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!