Reject Navigation Acknowledge popup using Watir

I am trying to disable the Confirm Navigation popup. Here's what it looks like in Chrome.

enter image description here

To view 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 

I am currently redefining 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 everything works fine. I'm just wondering if there is a better solution.

+8
javascript popup onbeforeunload watir-webdriver watir
source share
1 answer

I think the best way at the moment.

I filed an error / request function for this about two months ago. You can comment there and add a support vote if this is something that will facilitate your work.

+6
source share

All Articles