HtmlUnit 与 JS Executor 线程同步

发布于 2024-12-22 08:17:02 字数 151 浏览 2 评论 0原文

请耐心等待,因为我对 Java 比较陌生,对 HtmlUnit 也比较陌生。我想知道是否有办法使主线程与htmlunit的js执行器线程同步?问题是我想读取元素文本值,而更新这些值的 ajax 请求在后台运行。

可以在不修改 HtmlUnit 源代码的情况下完成此操作吗?

Please bear with me as I am relatively new to Java and even newer to HtmlUnit. I would like to know if there is a way to synchronize the main thread with the htmlunit's js executor thread? The problem is that I would like to read element text values while ajax requests that update those values are run in the background.

Can this be done without modifying the HtmlUnit's source code?

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

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

发布评论

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

评论(1

才能让你更想念 2024-12-29 08:17:02

我不确定这是否是您正在寻找的,但您可以在 HtmlUnit 的 WebClient 上设置 NicelyResynchronizingAjaxController,它将自动将您所有的异步调用转换为同步调用。这样就可以测试您的 AJAX 代码,而无需轮询或休眠任意时间,希望 AJAX 调用已完成。它并不是适用于所有情况的解决方案,但它通常非常有用。

I'm not sure exactly if that's what you're looking for, but you can set, on HtmlUnit's WebClient, an NicelyResynchronizingAjaxController, which will automatically transform all your asynchronous calls into synchronous calls. This enables testing your AJAX code without having to poll or sleep for an arbitrary time, hoping that the AJAX call has finished. It's not the solution for all cases, but it's often very useful.

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