我在处理表单提交的时候进行页面表单的抓取,官方给出的说明文档对表单提交写出如下文档:
@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();表单并没有提交,页面也没有进行跳转,请问这种情况如何处理,是我想错了吗?
@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();表单并没有提交,页面也没有进行跳转,请问这种情况如何处理,是我想错了吗?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货