0

私はきゅうりとカピバラが初めてで、次のエラーに困惑しています:

   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」ローカル変数を変更しているので、正規表現を変更する必要はないと思います。それとも私ですか?

4

1 に答える 1

0

firstandメソッドを使用して、findこのようにクリックを設定できます

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

また

When /^I click the "([^"]*)" button$/ do |button_text|
  find('.page a', :text => "#{button_text}").click
end
于 2013-07-22T09:08:54.123 に答える