HtmlUnit模擬頁面提交一個form

gbd8 9年前發布 | 2K 次閱讀 Java

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();

}</pre>

 本文由用戶 gbd8 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!