Skip to content

Instantly share code, notes, and snippets.

@bbugh
Created October 13, 2012 01:04
Show Gist options
  • Save bbugh/3882746 to your computer and use it in GitHub Desktop.
Save bbugh/3882746 to your computer and use it in GitHub Desktop.
Accessing alert box in JavaScript with Capybara/rails/rspec
//Get a reference to the alert using the following:
alert = page.driver.browser.switch_to.alert
// and then hit OK with
page.driver.browser.switch_to.alert.accept
// or dismiss it with
page.driver.browser.switch_to.alert.dismiss
// or get the text with
page.driver.browser.switch_to.alert.text
Copy link

ghost commented Jul 30, 2015

Tried the same but it is throwing below error.

`assert_ok': No alert is present (Selenium::WebDriver::Error::NoAlertPresentError)

@EricA-G
Copy link

EricA-G commented May 12, 2016

page.driver.browser.switch_to.alert.accept
and
page.driver.browser.switch_to.alert.dismiss
worked for me

@benlieb
Copy link

benlieb commented Jun 27, 2019

works for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment