日期:2014-05-18  浏览次数:20686 次

使用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赋值?????