2013-07-21 96 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