Accept Confirm Alert with Rspec, Capybara & Headless Chrome

While testing a feature that requires a confirmation, you may have seen a: Selenium::WebDriver::Error::UnhandledAlertError error.

There are two different ways to accept the confirm alert in an acceptance/feature spec:

  1. Access driver itself, sometime after the dialog is expected to appear:
page.driver.browser.switch_to.alert.accept
  1. Wrap your click event in an accept_confirm method:
page.accept_confirm do
  page.find(delete_btn).click
end

Hopefully this helps, Happy coding!