关闭“确认导航"Watir 的弹出窗口

我正在尝试关闭确认导航"弹出窗口.这就是它在 Chrome 中的样子.

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

要查看弹出窗口:

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

目前,当我访问该页面时,我会覆盖 onbeforeunload,正如 http 中所建议的那样://watirwebdriver.com/javascript-dialogs/

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.

推荐答案

我认为这是目前最好的方法.

I think that's the best way for now.

大约两个月前,我为此提交了 bug/feature-request.如果这会让您的事情变得更轻松,您可能想在那里发表评论并投支持票.

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.

相关文章