Capybara / Cucumber无法点击twitter bootstrap rails应用程序中的链接/按钮

时间:2012-06-28 20:13:44

标签: ruby-on-rails twitter-bootstrap cucumber capybara

好的,所以我很确定我在这里做了一些蠢事,但这里是我页面上按钮生成的HTML <a href="/courses/1" class="btn" id="Enroll in Course">Enroll in Course</a>

黄瓜步骤定义如下:

When /^I go to the course homepage$/ do 
  visit("/courses/#{@course.id}")
end 

Then /^I should see the "(.*?)" button$/ do |button|
  has_button?(button)
end

When /^I click on "(.*?)"$/ do |button| 
  click_on(button)
end

检查页面上是否存在按钮的第二步是完美无缺,但第三步是单击按钮,表示未找到按钮或链接(click_on应该处理按钮和链接) 。

知道为什么会这样吗?

我正在使用twitter bootstrap,这里是生成上面html的erb文件的片段:
<%= link_to 'Enroll in Course',course_path, :class => 'btn', :id => 'Enroll in Course' %>

任何帮助将不胜感激! 谢谢!

1 个答案:

答案 0 :(得分:3)

最糟糕的情况是,您可以通过其css选择器找到该元素并强制单击它。

find('#enrollInCourse').click