如何在HtmlUnit中获取textarea元素及其内容?

时间:2016-08-16 21:36:59

标签: java integration-testing htmlunit htmlunit-driver

我正在尝试使用javahtmlunit获取元素的内容,但会出现一些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/>

请指导。

0 个答案:

没有答案