我正在尝试使用java
和htmlunit
获取元素的内容,但会出现一些ClassCastException
错误。不确定我是否以正确的方式得到这个。
例外:
java.lang.ClassCastException: com.gargoylesoftware.htmlunit.html.HtmlMeta cannot be cast to com.gargoylesoftware.htmlunit.html.HtmlTextArea
at com.study.crud.web.it.htmlunit.PageIT.testCreateProductScenario(PageIT.java:34)
PageIT.java
@Test
public void testCreateProductScenario() throws IOException {
HtmlPage homePage = webClient.getPage(BASE_URL);
assertEquals(homePage.getWebResponse().getStatusCode(), SUCCESS_CODE); //verify home page
//verify search
HtmlPage createProductPage = homePage.getAnchorByText("Create Product").click();
assertEquals(createProductPage.getWebResponse().getStatusCode(), SUCCESS_CODE); //verify create product page
//search elements by id
HtmlInput nameTxtBox = createProductPage.getElementByName("name");
HtmlTextArea descTxtArea = (HtmlTextArea) createProductPage.getElementByName("description");
createProduct.jsp
<form class="form-horizontal" role="form" name="frmCreateProduct" method="POST" action="">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="name" placeholder="Enter Name"/>
</div>
<br/><br/>
<label for="description" class="col-sm-2 control-label">Description</label>
<div class="col-sm-10">
<textarea class="form-control" name="description" rows="5" cols="100" maxlength="1000"></textarea>
</div>
<br/><br/>
请指导。