Dismiss “Confirm Navigation” popup with Watir

无人久伴 提交于 2019-12-19 06:24:10

问题


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

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.


回答1:


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.



来源:https://stackoverflow.com/questions/9389379/dismiss-confirm-navigation-popup-with-watir

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!