2013-07-21 98 views
0

我是新来的黄瓜和水豚,我很困惑,出现以下错误:水豚和黄瓜CSS定位

When I click the "Search" button # features/step_definitions/web_steps.rb:9 
    Unable to find button #<Capybara::Element tag="button"> (Capybara::ElementNotFound) 
    ./features/step_definitions/web_steps.rb:11:in `/^I click the "([^"]*)" button$/' 
    features/search.feature:9:in `When I click the "Search" button' 

在我的特点,我有:

When I click the "Search" button 

我一步看起来像:

When /^I click the "([^"]*)" button$/ do |button_text| 
    button_text = find('#gbqfb') 
    click_button button_text 
end 

我试过'click(button_text)和click_link方法。我正在认清它可能很明显,我没有看到的东西。我试图找到一个按钮元素的CSS定位器,然后单击该元素。我认为正则表达式不需要改变,因为我改变了'button_text'局部变量。或者我?

回答

0

您可以使用firstfind方法,然后单击设置这样

first('.page a', :text => '2').click 
find('.page a', :text => '2').click 

您黄瓜

When /^I click the "([^"]*)" button$/ do |button_text| 
    first('.page a', :text => "#{button_text}").click 
end 

OR

When /^I click the "([^"]*)" button$/ do |button_text| 
    find('.page a', :text => "#{button_text}").click 
end