Dismiss "Confirm Navigation" popup with Watir
Asked Answered
W

1

8

I am trying to dismiss "Confirm Navigation" popup. This is how it looks like in Chrome.

enter image description here

To see the popup:

require "watir-webdriver"
browser = Watir::Browser.new
browser.goto "http://www.gravityforms.com/demo/wp-admin/admin.php?page=gf_new_form"
browser.text_field(:id => "user_login").set "demo"
browser.text_field(:id => "user_pass").set "demo"
browser.button(:id => "wp-submit").click
browser.refresh

At the moment I override onbeforeunload when I visit the page, as suggested at http://watirwebdriver.com/javascript-dialogs/

browser.execute_script("window.onbeforeunload = function() {};")

So, the script now looks like this:

require "watir-webdriver"
browser = Watir::Browser.new
browser.goto "http://www.gravityforms.com/demo/wp-admin/admin.php?page=gf_new_form"
browser.text_field(:id => "user_login").set "demo"
browser.text_field(:id => "user_pass").set "demo"
browser.button(:id => "wp-submit").click
browser.execute_script("window.onbeforeunload = function() {};")
browser.refresh

And it works just fine. I am just wondering if there is a better solution.

Words answered 22/2, 2012 at 5:8 Comment(0)
F
6

I think that's the best way for now.

I filed a bug/feature-request for this about two months back. You might want to comment there and add a vote of support if it's something that would make things easier for you.

Furor answered 22/2, 2012 at 6:24 Comment(1)
Thanks Chuck, added my comment there.Cliquish

© 2022 - 2024 — McMap. All rights reserved.