---
title: Interacting with a Javascript confirmation from Selenium
teaser: Driving the browser to click within a dialog box.
tags: web,javascript,testing
author: Gabe Berke-Williams
published_on: 2011-09-07
---

Ever needed to interact with a Javascript `confirm()` dialog? Here's how to do
it in Selenium from Cucumber:

```ruby
When /^I confirm the dialog$/ do
  page.driver.browser.switch_to.alert.accept
end

When /^I cancel the dialog$/ do
  page.driver.browser.switch_to.alert.dismiss
end
```
