获取用于水豚测试的下拉列表的选择值 [英] Get select value of dropdown for capybara testing

查看:24
本文介绍了获取用于水豚测试的下拉列表的选择值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须为网站编写测试.我正在尝试获取下拉框的选定值.到目前为止,我可以通过执行

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

返回 -不允许看电影GPG米R13R15R16R18电阻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

但这对我没有多大帮助,因为我试图从下拉框中获取所选项目的文本.

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屋!

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