RoR: How to test a confirm dialog with Capybara?

Capybara is a great Gem about integration tests in Ruby on Rail. It simulates how a real user would interact with your application by the browser.
This post explains how to face the javascript confirmation pop up windows (“Are you sure?”).
Seems like there is no way to handle it in Capybara but, If you’re using a drivers that supports JavaScript as Selenium, the best solution is override the confirm method to always return true.

page.evaluate_script('window.confirm = function() { return true; }')'Destroy')

About me

Giuseppe La Rosa

IT Specialist

Milan, Italy

Follow me on:


Hi, my name is Giuseppe La Rosa, I’m a System Engineer living in Milan (Italy). I was born in Catania (Italy) in 1978. I started to get interested in the world of computer science at the age of 8 years. I graduated in 2006 with a degree in Information Technology and then I attended a stage at New York University for 3 months in bioinformatics algorithms filed.
After that, I came back to Italy and I worked in several roles as Java Developer and System administrator. Now I am an Operations Business Manager in a big Telco company.
I have a deep passions in several fields related to IT as OS, languages, security, Cloud and much more.


OS: Linux, Unix, HP-UX, Oracle Exadata
Languages : Java (J2SE, J2EE, Servlet), Python, Ruby on Rails, Puppet, Shell scripting
Web languages: JSP, ASP, HTML, CSS, XML+DTD
Tools & other: HP Service Guard, Veritas Cluster, Veritas Volume Manager


RHCA (Red Hat Certified Architect)
Red Hat Certified System Administrator in OpenStack
Platform-as-a-Service: Red Hat OpenShift Enterprise
Red Hat Server Hardening
Red Hat Performance Tuning
RHCVA (Red Hat Certified Virtualization Administrator)
RHCE (Red Hat Certified Engineer)
ITIL V3 Foundation
Ec-Council Certified Ethical Hacker v7


Photo, Ju Jitsu and above all motorbike