读书人

使用HttpUnit时怎么向select控件赋值

发布时间: 2012-01-22 22:38:43 作者: rapoo

使用HttpUnit时,如何向select控件赋值?
假设某JSP中有select控件如下:
<select name= "color ">
<option value= "red "> Red </option>
<option value= "green "> Green </option>
<option value= "blue "> Blue </option>
</select>

我通过form.setParameter( "color ", "green ");赋值,却提示:
com.meterware.httpunit.IllegalParameterValueException: May not set parameter 'color ' to 'blue '. Value must be one of: { }

请同道指点,谢谢!

public void testExecute1() throws Exception
{
WebConversation wc = new WebConversation();
WebRequest request = new GetMethodWebRequest( "http://127.0.0.1:8088/struts-cookbook-1.3.8/ ");
WebResponse response = wc.getResponse(request);
WebLink link = response.getLinkWith( "Execute ");
assertNotNull( "superLink 'Execute ' is null ", link);

WebResponse responseOfExecute = link.click();
WebForm form = responseOfExecute.getFormWithID( "simpleForm ");
assertNotNull( "form 'simpleForm ' is null ", form);

assertTrue( "no parameter named 'color ' ", form.hasParameterNamed( "color "));
form.setParameter( "color ", "green "); // throws exception
}

[解决办法]
给select赋值?????

读书人网 >Java Web开发

热点推荐