Htmlunit:填写自动刷新的表单
我通常可以使用 HtmlUnit 填写表单并将其提交到服务器。美好的。
不幸的是,我不知道如何填写根据我在表单上设置的值刷新到服务器的特定表单。该表单似乎会刷新到服务器,因为为字段设置值时会触发一些 JavaScript...
举一个简单的例子,我有一个包含 2 个字段、下拉列表的表单,比方说国家和地区:当我从“国家/地区”字段中选择一个值时,页面会自动刷新到服务器(javascript)并显示相同的表单,其中“区域”字段更新为可能的值,具体取决于先前选择的“国家/地区”字段。
这是一个在线测试页面,其中包含我正在谈论的表格: http://web1.ciemme-service.it/html-unit.nsf /form?OpenForm
我想做的是: - 使用我必须填写的表格加载页面(有效) - 为字段“国家/地区”设置一个值(有效) - 等待页面刷新到服务器(由 javascript 自动完成...) - 为字段区域设置一个值 - 提交表格
感谢您给我的任何帮助/提示。
I can normally fill-in a form using an HtmlUnit and submit it to the server. Fine.
UnfortunateIy I don't know how to fill-in a specific form that refreshes to server depening on values I set on the form. That form seems to refreshes to the server because of some javascript that is triggered when a value is set for a field...
To make a simple example, I have a form with 2 fields, drop-down lists, let's say Country and Region: when I choose a value from field Country, the page automatically refreshes to the server (javascript) and shows the same form with field Region updated with possible values dependent on previous choice for field Country.
Here is an online test page with a form I am talking about:
http://web1.ciemme-service.it/html-unit.nsf/form?OpenForm
What I would like to do is:
- load the page with the form I have to fill-in (works)
- set a value for field Country (works)
- wait that page refreshes to the server (done by javascript automatically...)
- set a value for field Region
- submit the form
Thanks for any help/hints you can give me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想我找到了解决方案:实际上我必须将 WebClient 对象视为真正的网络浏览器!
设置国家/地区字段的值后,我等待几秒钟以进行刷新(javascript),然后从 webClient 对象获取当前的 HtmlPage(刷新的页面!)并继续处理新页面(为区域字段 + 单击提交按钮):
这是一个示例:
希望有帮助!
更多测试正在进行中...;-)
I guess I found the solution: actually I have to think to WebClient object as a real web browser!
After I set the value for Country field, I wait some seconds for the refresh to happen (javascript), then I get the current HtmlPage from the webClient object (the refreshed page!) and continue working on the new page (set a value for Regione field + click on the submit button):
Here's an example:
Hope it helps!
More testing ongoing... ;-)
你可能想看看这个页面,它显示了如何等待ajax回复
另请参阅有关类似主题的此问题
you might want to take a look at this page which shows how you can wait for ajax response
see also this question on a similar topic