htmlunit表单提交求教

坚强的马铃薯 2011-07-20 12:13:52
我在处理表单提交的时候进行页面表单的抓取,官方给出的说明文档对表单提交写出如下文档:
@Test
public void submittingForm() throws Exception {
final WebClient webClient = new WebClient();

// Get the first page
final HtmlPage page1 = webClient.getPage("http://some_url");

// Get the form that we are dealing with and within that form,
// find the submit button and the field that we want to change.
final HtmlForm form = page1.getFormByName("myform");

final HtmlSubmitInput button = form.getInputByName("submitbutton");
final HtmlTextInput textField = form.getInputByName("userid");

// Change the value of the text field
textField.setValueAttribute("root");

// Now submit the form by clicking the button and get back the second page.
final HtmlPage page2 = button.click();

webClient.closeAllWindows();
}
我们看到在这种情况下这句代码 final HtmlSubmitInput button = form.getInputByName("submitbutton");
应该就是对表单中<input type="submit".......>这个元素进行抓取,然后通过button.click();进行表单提交,但是我发现例如163邮箱登录,表单中的提交按钮是<button .....>而不是<input type=......>那么
对提交按钮的抓取就不能用final HtmlSubmitInput button = form.getInputByName("submitbutton");那我们要取得提交按钮是不是应该如下:HtmlButton button = form.getButtonByName(""); 可是我实际情况是,通过这种方式取得的提交按钮,执行button.click();表单并没有提交,页面也没有进行跳转,请问这种情况如何处理,是我想错了吗?
...全文
271 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lilei9963 2011-12-08
  • 打赏
  • 举报
回复
是否可以用 getByXPath("//button");来实现

就是直接取 button这个村签来完成呢?可以试一下。

wzy42563 2011-07-20
  • 打赏
  • 举报
回复
我就看看 不说话
zn85600301 2011-07-20
  • 打赏
  • 举报
回复
每种网页处理机制不同 还有的是一个图片 上面写了onclick事件 在事件里面提交
坚强的马铃薯 2011-07-20
  • 打赏
  • 举报
回复
=.=

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧