如何使用Capybara访问Bootstrap-Dropdown-Elements?

时间:2013-11-16 19:35:02

标签: ruby-on-rails rspec tdd capybara

我目前正在尝试访问标题部分内部的bootstrap-dropdown菜单中的一些文本字段,似乎capybara找不到这些元素。这是我的代码,我真的不知道我做错了什么:/

这是我的下拉菜单:

<li id="fat-menu" class="dropdown">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown">
          Sign in <b class="caret"></b></a>
      <ul class="dropdown-menu">
          <%= form_for(:session, url: sessions_path) do |f| %>

          <li><%= f.label :email %></li>
          <li><%= f.text_field :email %></li>
          <li><%= f.label :password %></li>
          <li><%= f.password_field :password %></li>
          <li><%= f.submit "Sign in",class: "btn btn-large btn-primary" %></li>

                          <% end %>
                        </ul>
                    </li>

这是我的Utilitie功能,我想访问文本域:

include ApplicationHelper

    def sign_in(user, options={})
      if options[:no_capybara]
        # Sign in when not using Capybara.
        remember_token = User.new_remember_token
        cookies[:remember_token] = remember_token
        user.update_attribute(:remember_token, User.encrypt(remember_token))
      else
        visit root_url
        find("a.dropdown-toggle").click
        fill_in "Email",    with: user.email
        fill_in "Password", with: user.password
        click_button "Sign in"
      end
    end

这是我收到的错误消息..

Failure/Error: sign_in user
     Capybara::ElementNotFound:
       Unable to find field "Email"
     # ./spec/support/utilities.rb:12:in `sign_in'
     # ./spec/requests/user_pages_spec.rb:11:in `block (3 levels) in <top (required)>'

0 个答案:

没有答案