使用 xpath 从选择列表中获取值
不起作用
puts $browser.select_list(:xpath,"//*[@id='numType']").exists?
number = $browser.select_list(:xpath,"//*[@id='numType']").options.map(&:text)
number_list = Array.new
number.each do |number_text|
number_list << "#{number_text}"
end
我正在尝试使用 xpath 获取选择列表值,因为 by id 在存在函数中给了我 false,但HTML 代码
<div id="forwardRs">
<div class="forwardR">
<div id="forwardT" class="rc1">
<select id="forward_types" name="Foward Types" tabindex="5" onchange="changeForwardTypes(this);">
<option value="unconditional">unconditional</option>
<option value="busy">busy</option>
<option value="reply">reply</option>
<option value="reachable">reachable</option>
<option value="other">other</option>
</select>
</div>
<div id="numtype" class="rc1" style="">
<select id="numType" onchange="changeNumType(this);" name="numbers" tabindex="5">
<option value="ex">Ex</option>
<option value="in">In</option>
</select>
</div>
<div id="rule" class="rc1" style="">
<input id="tel" type="text" value="" size="20" name="tel" tabindex="2" onchange="changeNumberRule(this);">
</div>
<div id="removeForwardRule" class="rc3">
<a onclick="removeForwardRule(this);">
<img src="../../images/delete.png">
</a>
:
我该怎么做?
坦克
I'm trying to get the select list values using xpath because by id is giving me false in the exists function, but is not working
puts $browser.select_list(:xpath,"//*[@id='numType']").exists?
number = $browser.select_list(:xpath,"//*[@id='numType']").options.map(&:text)
number_list = Array.new
number.each do |number_text|
number_list << "#{number_text}"
end
HTML code:
<div id="forwardRs">
<div class="forwardR">
<div id="forwardT" class="rc1">
<select id="forward_types" name="Foward Types" tabindex="5" onchange="changeForwardTypes(this);">
<option value="unconditional">unconditional</option>
<option value="busy">busy</option>
<option value="reply">reply</option>
<option value="reachable">reachable</option>
<option value="other">other</option>
</select>
</div>
<div id="numtype" class="rc1" style="">
<select id="numType" onchange="changeNumType(this);" name="numbers" tabindex="5">
<option value="ex">Ex</option>
<option value="in">In</option>
</select>
</div>
<div id="rule" class="rc1" style="">
<input id="tel" type="text" value="" size="20" name="tel" tabindex="2" onchange="changeNumberRule(this);">
</div>
<div id="removeForwardRule" class="rc3">
<a onclick="removeForwardRule(this);">
<img src="../../images/delete.png">
</a>
How can i do this?
Tanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
忽略我最初在这里写的内容,因为我完全没有成功地让
.options
方法返回选择列表中的任何选项,而.selected_options
方法返回所选择的选项就好了。我已经能够通过执行以下操作成功地从您的选择列表中获取选项:
这为您提供了选择列表中的选项数组。
为了从这些元素中获取文本,我没有给出
一个非常漂亮的答案,但是嘿。
我真的不知道为什么
.options
对我不起作用,但您可能遇到同样的问题。Disregard what I originally wrote here, as I have been completely unsuccessful in getting the
.options
method to return any of the options in a select list, whereas the.selected_options
method returns the selected options just fine.I've been able to successfully get the options from your select list by doing the following:
which gives you an array of the options in the select list.
To get the text out of those elements I did
Not a very pretty answer but hey.
I have literally no idea why
.options
does not work for me, but you may be suffering the same problem.我已经使用问题中的 html 创建了 html 文件,出于某种原因,我的 Firefox 8 认为
option
标签不在select
标签内。请参阅随附的屏幕截图。I have created html file with the html from the question, and my Firefox 8 for some reason thinks that
option
tags are not insideselect
tag. See attached screen shot.