关闭“确认导航”与 Watir 一起弹出

发布于 2025-01-07 12:13:06 字数 1149 浏览 1 评论 0原文

我试图关闭“确认导航”弹出窗口。这就是 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

目前,当我访问页面,如 http://watirwebdriver.com/javascript-dialogs/ 建议的那样

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

,现在的脚本看起来像这样:

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

而且效果很好。我只是想知道是否有更好的解决方案。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋心╮凉 2025-01-14 12:13:06

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

大约两个月前,我为此提交了一个bug/feature-request。如果这能让你的事情变得更容易,你可能想在那里发表评论并添加支持票。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文