使用Capybara + Rails3找不到要单击的元素 [英] Can't find element to click on using Capybara + Rails3
本文介绍了使用Capybara + Rails3找不到要单击的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
背景:我正在使用Capybara和Rspec来测试Rails 3应用。
使用的驱动程序:硒
Background: I'm using Capybara with Rspec to test a Rails 3 app. Driver used: Selenium
问题:
我找不到登录按钮,以便在我的测试中单击。
Problem: I can't find the "Sign in" button in order to click on from within my test.
HTML代码:
<form accept-charset="UTF-8" action="/" class="filter_form" id="login" method="post">
<fieldset>
<div class="modal-body">
<div class="clearfix login-fields">
<label for="user_email">Email</label>
<div class="input login-inputs">
<input class="input-text" id="user_email" name="user[email]" placeholder="email" size="30" type="email" value="">
</div>
</div>
<div class="clearfix login-fields">
<label for="user_password">Password</label>
<div class="input login-inputs">
<input class="input-text" id="user_password" name="user[password]" placeholder="password" size="30" type="password">
</div>
</div>
</div>
<div class="modal-footer">
<input class="btn btn-primary login_btn" id="btn_login" name="commit" type="submit" value="Sign in">
<a href="/lms/forgot_password" class="btn">Forgot password...</a>
<a href="#" class="btn close cancel" data-dismiss="modal">Cancel</a>
</div>
</fieldset>
</form>
失败测试
it "should login correctly if the right credentials are given", :js => true do
Capybara.default_wait_time = 5
Capybara.reset_sessions!
visit '/'
click_link('login_link') #this will bring a modal window with the code posted above using js
within("#login") do
fill_in 'user_email', :with => "my-email@example.com"
fill_in 'user_password', :with => "mypwd"
end
response.should have_selector('input#btn_login') #This passes
click_on("input#btn_login") #Here it fails, saying it can't find an element with that selector
response.should have_selector(:xpath, '//div[@class="alert-message block-message info"]')
end
我的测试文件位于 spec / requests
之内。
My test file is inside spec/requests
.
有什么想法吗?
谢谢!
Any ideas? Thanks!
推荐答案
请尝试以下操作:
page.find("#btn_login").click
这篇关于使用Capybara + Rails3找不到要单击的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文