关闭“确认导航”与 Watir 一起弹出
我试图关闭“确认导航”弹出窗口。这就是 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.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这是目前最好的方法。
大约两个月前,我为此提交了一个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.