Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby Cucumber如何模拟多个下拉选择?_Ruby_Ruby On Rails 3_Drop Down Menu_Cucumber_Capybara - Fatal编程技术网

Ruby Cucumber如何模拟多个下拉选择?

Ruby Cucumber如何模拟多个下拉选择?,ruby,ruby-on-rails-3,drop-down-menu,cucumber,capybara,Ruby,Ruby On Rails 3,Drop Down Menu,Cucumber,Capybara,嗨,我是Cucumber和RubyonRails新手,我不知道如何模拟多个下拉菜单选择。我可以通过一个下拉菜单(在我的例子中是“评级”)来完成 我认为与我的问题相关的错误是 cannot select option, no select box with id, name, or label 'Released On' found (Capybara::ElementNotFound) (eval):2:in `select' ./step_definitions/web

嗨,我是Cucumber和RubyonRails新手,我不知道如何模拟多个下拉菜单选择。我可以通过一个下拉菜单(在我的例子中是“评级”)来完成

我认为与我的问题相关的错误是

cannot select option, no select box with id, name, or label 'Released On' found (Capybara::ElementNotFound)
      (eval):2:in `select'
      ./step_definitions/web_steps.rb:86:in `/^(?:|I )select "([^"]*)" from "([^"]*)"$/'
      filter_movie_list.feature:9:in `Given the following movies exist:'
我相信我的web应用程序中的相关源代码是

    <label for="movie_title">Title</label>
    <input id="movie_title" name="movie[title]" size="30" type="text" />
    <label for="movie_rating">Rating</label>
    <select id="movie_rating" name="movie[rating]"><option value="G">G</option>
    <option value="PG">PG</option>
    <option value="PG-13">PG-13</option>

    <option value="R">R</option>
    <option value="NC-17">NC-17</option></select>
    <label for="movie_release_date">Released On</label>
    <select id="movie_release_date_1i" name="movie[release_date(1i)]">
    <option value="2007">2007</option>
    <option value="2008">2008</option>

    < And so on ...>

    </select>
    <select id="movie_release_date_3i" name="movie[release_date(3i)]">
    <option value="1">1</option>

    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>

    < And so on ...>

    </select>
    <input name="commit" type="submit" value="Save Changes" />

如果它起作用的话。但我想不会,因为我认为ruby知道如何处理日期。谢谢您的时间。

问题在于,已发布的标签上有
for=“movie\u release\u date”
选择框中有
id=“movie\u release\u date\u 1i”
id
值必须匹配,以便Capybara根据标签文本定位字段

可能的解决方案:

1)如果您可以控制HTML,请更正它。

And   %Q{I select "#{movie[:release_date]}" from "movie_release_date_1i"}
您想要:

<label for="movie_release_date">Released On</label>
<select id="movie_release_date" name="movie[release_date(1i)]">

只有当ID或名称是静态的(即末尾的数字始终相同,而不是每次加载页面时随机生成)时,此选项才起作用

3)直接使用水豚,而不是使用web\u步骤。rb

如果您直接使用Capybara,而不是使用web_steps.rb(我假设您的步骤都来自web_steps.rb),那么您将获得更多用于定位select字段的选项(例如xpath)

<label for="movie_release_date">Released On</label>
<select id="movie_release_date" name="movie[release_date(1i)]">
<label for="movie_release_date_1i">Released On</label>
<select id="movie_release_date_1i" name="movie[release_date(1i)]">
And   %Q{I select "#{movie[:release_date]}" from "movie_release_date_1i"}
And   %Q{I select "#{movie[:release_date]}" from "movie[release_date(1i)]"}