Bilal Basharat
Bilal Basharat

Reputation: 3376

javascript alert .press 'Ok' with capybara and cucumber test case

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")

Upvotes: 3

Views: 3912

Answers (2)

Neal
Neal

Reputation: 4568

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; }')

Upvotes: 0

Jon M
Jon M

Reputation: 11705

Get a reference to the alert using the following:

alert = page.driver.browser.switch_to.alert

And then

alert.accept

To hit 'Ok'

Upvotes: 12

Related Questions