将 select_list 选项转换为 watir-webdriver 中的字符串数组? [英] Turning a select_list options into a string array in watir-webdriver?

查看:16
本文介绍了将 select_list 选项转换为 watir-webdriver 中的字符串数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检查选择列表下拉列表的内容,该下拉列表因另一个字段中的值而异.我正在将有效选项读入 CVS 字段中的字符串数组,并通过执行以下操作进行比较;

I need to check the contents of a select list drop down which varies depending on a value in another field. I am reading the valid options into an array of strings from a CVS field and comparing by doing the following;

selectContent = []
$browser.select_list(:id,"srch-status-select").options.each {|option| selectContent << option.text}
assert_equal(validContent,selectContent,"Status drop down has wrong values")

这是正确的还是现有的 select_list 方法可以进行类似的转换?

Is this correct or is there an existing select_list method which does a similar conversion?

推荐答案

没有方法可以完全按照您的意愿行事,但更简洁的版本是:

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)

这篇关于将 select_list 选项转换为 watir-webdriver 中的字符串数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆