diff --git a/lib/click_govuk_button.rb b/lib/click_govuk_button.rb index 599a4e6..2dea333 100644 --- a/lib/click_govuk_button.rb +++ b/lib/click_govuk_button.rb @@ -16,6 +16,10 @@ def click @buttons = page.all('a.govuk-button', text: button_text, exact_text: true) end + if @buttons.empty? + @buttons = page.all("input[type=submit][value=\"#{Capybara::Selector::CSS.escape(button_text)}\"]") + end + if @buttons.size == 0 check_for_inexact_match raise "Unable to find button \"#{button_text}\"" diff --git a/spec/click_govuk_button_spec.rb b/spec/click_govuk_button_spec.rb index 4254204..71bfbdb 100644 --- a/spec/click_govuk_button_spec.rb +++ b/spec/click_govuk_button_spec.rb @@ -30,6 +30,18 @@ end end + context "where there is an input with type=submit" do + before do + TestApp.body = '
' + visit('/') + end + + it 'should submit the form' do + click_govuk_button('Continue') + expect(page.current_path).to eql("/success") + end + end + context "where there are 2 buttons with the same text" do before do TestApp.body = ' '