Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dismiss "Confirm Navigation" popup with Watir

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.

like image 774
Željko Filipin Avatar asked Feb 22 '12 05:02

Željko Filipin


1 Answers

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.

like image 122
Chuck van der Linden Avatar answered Nov 05 '22 07:11

Chuck van der Linden