Firewatir:更改选择列表中的选择时出现问题
我是 FireWatir 的新手,在更改选择列表中的选择时遇到一些问题。 HTML 如下所示:
<div id="softwarelist">
<select name="TDSOFTWARE" style='width:191;'>
<option value="QFX">Quicken 2004 or newer-Windows
<option value="QIF">Quicken 2003 or older-Windows
<option value="OFX">Microsoft Money 98 or newer
<option value="QIF">Microsoft Money 97 or older
<option value="CSV">Microsoft Excel
</select>
</div>
我需要将选择更改为 CSV。
这是我的脚本中陷入困境的一行:
browser.div(:id, "softwarelist")
我随机尝试了各种方法,但(显然)没有一个有效。使用“show_all_objects”方法,如下所示:
puts browser.div(:id, "softwarelist").show_all_objects
我得到了所有各种格式的列表...这让我相信我至少是在正确的范围内,但实际上我不知道,因为我是使用 FireWatir 的新手。
有人能指出我正确的方向吗?
I'm new to FireWatir and having some issues changing a selection in a select list. Here's what the HTML looks like:
<div id="softwarelist">
<select name="TDSOFTWARE" style='width:191;'>
<option value="QFX">Quicken 2004 or newer-Windows
<option value="QIF">Quicken 2003 or older-Windows
<option value="OFX">Microsoft Money 98 or newer
<option value="QIF">Microsoft Money 97 or older
<option value="CSV">Microsoft Excel
</select>
</div>
I need to change the selection to CSV.
Here's the line in my script where I am stuck:
browser.div(:id, "softwarelist")
I've sort of randomly tried various methods, but (obviously) none have worked. Using the method 'show_all_objects', like so:
puts browser.div(:id, "softwarelist").show_all_objects
I get a list of all the various formats... that leads me to believe I am in the right ballpark at least, but really I have no idea as I am new to working with FireWatir.
Can anyone point me in the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样的东西应该有效(未经测试):
有关更多信息,请查看选择框 页面。
Something like this should work (not tested):
For more information take a look at Selection Boxes page at Watir Wiki.
您的问题是您试图将包含选择列表的 div 视为选择列表。所以你试图操纵错误的对象。您处于“关闭”状态,因为这是列表周围的外部容器,因此 show_all_objects 将报告位于该 div 内部的列表。
Zeljko 答案中的代码应该对你有用。
Your problem is that you are trying to treat the div, which contains the selection list, as if it was the selection list. So you are trying to manipulate the wrong object. you are 'close' because that's the outer container around the list, so show_all_objects will report on the list, which is inside that div.
the code in Zeljko's answer ought to work for you.