3

i am using caoybara , selenium and cucumber . i wana click an alert box with 'ok' button. help me out this code is not clicking the button:

page.evaluate_script('window.confirm = function() { return true; }')
page.click("Ok")
Bilal Basharat
  • 3,066
  • 6
  • 21
  • 20

2 Answers2

12

Get a reference to the alert using the following:

alert = page.driver.browser.switch_to.alert

And then

alert.accept

To hit 'Ok'

Jon M
  • 11,669
  • 3
  • 41
  • 47
0

Jon's didn't work for me probably because I'm using a newer version of capybara (2.1.0)

This worked for me:

page.evaluate_script('window.confirm = function() { return true; }')
Neal
  • 4,468
  • 36
  • 33