Webrat error on form submit

I was getting a bizarre error from Webrat:

    And I press "Next"                                                     # features/step_definitions/webrat_steps.rb:10
      You have a nil object when you didn't expect it!
      The error occurred while evaluating nil.submit (NoMethodError)
      (eval):2:in `click_button'
      ./features/step_definitions/webrat_steps.rb:12:in `/^I press "(.*)"$/'
      features/choosing_varieties.feature:39:in `And I press "Next"'

It turns out, my HTML tags were not nested properly… I had a <table><form></table></form> kind of situation.  If you’re getting an error like this, try validating your HTML.

Tags: , ,

7 Responses to “Webrat error on form submit”

  1. Julian Says:

    Erik - thank you very much for making the effort to write this. You just saved me hours. The only other google result was a lighthouse ticket saying the error comes from having no form. I had a form_for, but I started a div inside the form_for and closed it after the end.

  2. hooly scraps » webrat click_button error Says:

    [...] the form_for block and closed after the end. I fixed that and now cucumber is all green. Thanks to this post for pointing to the [...]

  3. Enoch Says:

    Thanks! This saved my head from being hit against the wall repeatedly.

  4. ranska Says:

    Merci
    It’s help me a lot

  5. erndEnson Says:

    thx for sharing this!!

  6. martinsson Says:

    my code passed html validation 401 strict, but I had a button without a surrounding form :

    once I changed to :

    It was ok

  7. The Bull Og » Blog Archive » A Tip for Webrat Says:

    [...] being able to decipher that, I turned to the web and found this helpful link which didn’t completely solve my problem but did point me in the right direction: check the [...]

Leave a Reply