获取下拉菜单的选择值以进行水豚测试 [英] Get select value of dropdown for capybara testing
问题描述
我必须为网站编写测试。我正在尝试获取下拉框的选定值。到目前为止,我可以通过以下操作获取下拉列表的内容
I have to write tests for a web site. I am trying to get the selected value of a dropdown box. So far i can get the contents of the dropdown by doing
find_field('restrictions__rating_movies').text
返回-
不允许电影
G
PG
M
R13
R15
R16
R18
R
RP16
允许所有电影
returns - Don't Allow Movies G PG M R13 R15 R16 R18 R RP16 Allow All Movies
我可以获取所选对象的值。
I can get the value of the selected object.
find_field('restrictions__rating_movies').value
返回-
1000
returns - 1000
这对我没有多大帮助但是,因为我试图从下拉框中获取所选项目的文本。
This does not help me much though because i am trying to get the text of the selected item from a drop down box.
<select class="" id="restrictions__rating_movies" name="restrictions[][rating_movies]">
<option value="0">Don't Allow Movies</option>
<option value="100">G</option>
<option value="200">PG</option>
<option value="300">M</option>
<option value="325">R13</option>
<option value="350">R15</option>
<option value="375">R16</option>
<option value="400">R18</option>
<option value="500">R</option>
<option value="600">RP16</option>
<option value="1000" selected="selected">Allow All Movies</option></select>
在这种情况下,我需要获取允许所有电影的值,我尝试了多种组合上面两个示例中的一个。
in this case shown i need to get the value 'Allow All Movies' I have tried many different combinations of the above two examples.
推荐答案
find_field('restrictions__rating_movies').find('option[selected]').text
这篇关于获取下拉菜单的选择值以进行水豚测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!