我有一个rspec测试试图以弹出模式形式填写一个字段。相关的行是
fill_in 'Name', with: 'Jo Blo'
,错误消息是
Capybara::ElementNotFound:
Unable to find visible field "Name" that is not disabled
这意味着它正在查找该字段但将其视为已禁用。但是,如果我使用capybara-screenshot查看失败时的页面,则该字段可见,该字段的html为
<div class="field">
<label for="user_name">Name</label><sup>*</sup><br>
<input type="text" name="user[name]" id="user_name">
</div>
即没有禁用。
该字段位于div#modal_new_user
。如果我将测试更改为
expect(page).to have_css '#modal_new_user'
fill_in 'Name', with: 'Jo Blo'
错误消息变为
Failure/Error: expect(page).to have_css '#modal_new_user'
expected to find visible css "#modal_new_user" but there were no
matches. Also found "", which matched the selector but not all filters.
这似乎意味着没有找到模态,但是再次,如果我看一下capybara截图,模态的html是可见的。 我该如何解决这个问题?
我使用的是capybara 3.0.2和rspec-rails 3.7.2。
bootstrap模式的代码是
<div id='modal_new_user' class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Warning</h4>
<p>enter code here Right now there is a 10 day free trial. Just fill in the form below.</p>
</div>
<div class="modal-body">
<form class="edit_user" id="edit_user_12004" action="/users" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="✓" /><input type="hidden" name="authenticity_token" value="306T/5kB9pqb9sW6mdW+tXyCzfydEF2tf8wQMJXEICO5uQ/YEDVVYqg12l7Qe+lU4uELZy/d1VIhzZObk/FVcQ==" />
<div class="field">
<label for="user_name">Name</label><sup>*</sup><br />
<input type="text" name="user[name]" id="user_name" />
</div>
<div class="field">
<label for="user_email">Email</label><sup>*</sup><br />
<input type="email" name="user[email]" id="user_email" />
</div>
<div class="field">
<label for="user_password">Password</label><sup>*</sup><br />
<input type="password" name="user[password]" id="user_password" />
</div>
<p id="terms">By creating your account, you are agreeing to the site <a target="_blank" href="/legal">Terms and Conditions</a>. You will not be spammed, we dislike spam as much as you do.
</p>
<input type="hidden" value="clubs#edit" name="user[referral]" id="user_referral" />
<div class="actions">
<input type="submit" name="commit" value="Join Now" class="btn btn-cta btn-cta-primary" data-disable-with="Join Now" />
</div>
</form> </div>
<div class="modal-footer right_close_button">
<button type="button" class="btn btn-info" data-dismiss="modal">Close</button>
</div>
</div>