Toxic Elephant

Don't bury it in your back yard!

Make Capybara use HTML5 with Rack::Test

Posted by matijs 04/10/2026 at 15h01

For Rails applications, you probably want to serve HTML5, and you only want to support browsers that support HTML5. And even if you must support older browsers, you probably want to make sure your application works for HTML5-compliant browsers.

If you’re using Capybara with the Selenium driver, this will happen automatically if the headless browser is HTML5-compliant. This introduces some overhead, so I try to use the Rack::Test driver if I can get away with it. Unfortunately, when using the Rack::Test driver, Capybara processes the HTML as HTML4. This can hide bugs in your HTML.

For example, when nesting button_to inside a form_for block, the form end tag emitted by button_to will close the form in HTML5. These means that any submit button that follows it will not work in a modern browser. However, Capybara with Rack::Test will not notice this.

The solution is to tell Capybara to use HTML5 with the Rack::Test driver by setting Capybara.use_html5_parsing = true.

no comments no trackbacks