HtmlUnit 在 window.open 之后停止 JavaScript 执行
我最近从 HTMLUnit 2.4 更新到 2.5(我们会选择最新版本,但由于已弃用的 API,有很多代码需要重构)。我现在遇到一些打开窗口的 JavaScript 问题。
正在测试的页面是报告的“加载屏幕时请稍候”。该页面打开一个新窗口,然后重定向回最初启动打印的页面。
所以 JavaScript 看起来像这样:
window.open(url,'report_window');
document.location.href = original_url;
使用 HtmlUnit 2.4,脚本将继续执行,如果我抓取原始 Window 对象,它将执行重定向。但是,升级到 HtmlUnit 2.5 后,原始窗口仍然位于“请稍候”页面上 - 重定向从未执行。看起来好像 JavaScript 在调用 window.open 之后停止执行。
如果我手动测试,我已经确认页面行为正确。我还在 window.open 调用之后尝试了不同的 JavaScript,以确认该特定调用不是问题。
有人知道这样的问题以及任何潜在的解决方法吗?由于 jQuery 兼容性,我们必须保留 HtmlUnit 2.5。
I've recently updated from HTMLUnit 2.4 to 2.5 (we'd go for the latest version but there is a lot of code to refactor due to the deprecated APIs). I'm now having a problem with some JavaScript that opens a window.
The page under test, is a 'Please wait while loading screen' for reports. The page opens a new window then redirects back to page that originally launched the print.
So the JavaScript looks something like:
window.open(url,'report_window');
document.location.href = original_url;
With HtmlUnit 2.4 the script would continue executing and if I grabbed the original Window object it would have performed the redirect. However, after upgrading to HtmlUnit 2.5, the original window is still on the 'Please wait' page - the redirect is never executed. It appears as though the JavaScript stopped executing after the call to window.open.
I have confirmed the page behaves correctly if I test manually. I've also tried different JavaScript after the window.open call to confirm that that particular call is not the issue.
Is anyone aware of an issue like this and any potential workarounds? We have to stay on HtmlUnit 2.5 because of jQuery compatibility.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够通过从 WebClient 对象上的 Web 窗口侦听器中删除 CurrentWindowTracker 对象来解决此问题。不幸的是,这个字段被完全封装了,所以我不得不通过反射来检索它。
I was able to fix this issue by removing the CurrentWindowTracker object from the web window listeners on the WebClient object. Unfortunately, this field is completely encapsulated, so I had to retrieve it via reflection.