本文整理匯總了Java中com.gargoylesoftware.htmlunit.html.HtmlForm.getOneHtmlElementByAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Java HtmlForm.getOneHtmlElementByAttribute方法的具體用法?Java HtmlForm.getOneHtmlElementByAttribute怎麽用?Java HtmlForm.getOneHtmlElementByAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.gargoylesoftware.htmlunit.html.HtmlForm
的用法示例。
在下文中一共展示了HtmlForm.getOneHtmlElementByAttribute方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testCreateTasks
import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入方法依賴的package包/類
@Test
public void testCreateTasks() throws Exception {
HtmlPage createTaskPage = webClient.getPage("http://localhost:8080/tasks/new");
HtmlForm form = createTaskPage.getHtmlElementById("form");
HtmlTextInput nameInput = createTaskPage.getHtmlElementById("name");
nameInput.setValueAttribute("My first task");
HtmlTextArea descriptionInput = createTaskPage.getHtmlElementById("description");
descriptionInput.setText("Description of my first task");
HtmlButton submit = form.getOneHtmlElementByAttribute("button", "type", "submit");
HtmlPage taskListPage = submit.click();
Assertions.assertThat(taskListPage.getUrl().toString()).endsWith("/tasks");
// String id = taskListPage.getHtmlElementById("todolist").getTextContent();
// assertThat(id).isEqualTo("123");
// String summary = newMessagePage.getHtmlElementById("summary").getTextContent();
// assertThat(summary).isEqualTo("Spring Rocks");
// String text = newMessagePage.getHtmlElementById("text").getTextContent();
// assertThat(text).isEqualTo("In case you didn't know, Spring Rocks!");
}
示例2: submitForm
import com.gargoylesoftware.htmlunit.html.HtmlForm; //導入方法依賴的package包/類
/**
* Submits a form.
*
* @param form
* The form to submit.
* @return The page to which the form redirects.
* @throws IOException
* If an IO error occurs
*/
protected final HtmlPage submitForm(HtmlForm form) throws IOException {
HtmlSubmitInput submit = form.<HtmlSubmitInput>getOneHtmlElementByAttribute("input", "type", "submit");
return submit.click();
}